Welcome Guest, Not a member yet? Register   Sign In
Ignited DataTables

[eluser]Unknown[/eluser]
great library! thanks!

[eluser]Unknown[/eluser]
Thanks! The first suggestion fixed my woes, however instead of the second change:

$sSearch = $this->ci->db->escape($this->ci->input->post('sSearch'));

for

$sSearch = $this->ci->input->post('sSearch');


[quote author="laxdoctor" date="1338409544"]DiLer - I'm having the same exact problem. When I directly access my controller that produces the json I see the correct data output. I was also able to get it to work when I set bServerSide to false.

EDIT 2: I made two changes to get this to work.

First, set add "sServerMethod": "POST" so your script looks something like:

Code:
$(document).ready(function() {
$('#test_table').dataTable( {
  "bProcessing": true,
  "bServerSide": true,
  "sServerMethod": "POST",
  "sAjaxSource": "/index.php/tables/listener"
} );
} );

Second, change Line 295 of the datatables library

From:
Code:
if($sSearch != '')

To:
Code:
if($sSearch != 0 && $sSearch != '')
[/quote]

[eluser]virtualgadjo[/eluser]
hi,

in case it helps anybody here, i've made a little change in the get_paging function
Code:
protected function get_paging()
{
$iStart = $this->ci->input->post('iDisplayStart');
$iLength = $this->ci->input->post('iDisplayLength');
if ( $iLength != '-1' )
{
  $this->ci->db->limit($iLength != '' ? $iLength : 100, ($iStart)? $iStart : 0);
}
}
the former function prevented the -1 (see all) trick from working, limiting the result amount to 100
of course, to be used cautiously if ever you deal with 100,000 + rows table (i often have to...)

have swing

[eluser]ZaLiTHkA[/eluser]
So I've hit a bit of a wall here... I'm pulling data from a SQL2008 DB into a datatable, I was doing table data server-side previously, but considering the overall dynamic feel of the page, I decided to switch over to using AJAX for loading the data instead.

Problem is, I need the complete results of the query inserted into my table, but I'm only getting the first 100... Looking in the JSON data returned, it does know that there are more rows (it says 2849 records), but I can't figure out how to get them all in. Any suggestions?

[eluser]virtualgadjo[/eluser]
Hi,

have a look at my post just abose Smile

this function is in the query generate function of the library...
if you don't want any limit to your query just transform it into this
Code:
protected function get_paging()
{
$iStart = $this->ci->input->post('iDisplayStart');
$iLength = $this->ci->input->post('iDisplayLength');
if ( $iLength != '-1' && $iLength != '' )
{
  $this->ci->db->limit($iLength, ($iStart)? $iStart : 0);
}
}
and i guess you won't have anymore limitation even for your first query
now, i don't really understand why you use ajax to load the whole data as in this case it would be more suitable to use datatables native progressive enhancement, that to say, load the whole stuff with ci and then apply datatables to the loaded table

but well, nevermind, this should work

have swing

[eluser]ZaLiTHkA[/eluser]
[quote author="virtualgadjo" date="1343833378"]Hi,

have a look at my post just abose Smile

this function is in the query generate function of the library...
if you don't want any limit to your query just transform it into this
Code:
protected function get_paging()
{
$iStart = $this->ci->input->post('iDisplayStart');
$iLength = $this->ci->input->post('iDisplayLength');
if ( $iLength != '-1' && $iLength != '' )
{
  $this->ci->db->limit($iLength, ($iStart)? $iStart : 0);
}
}
and i guess you won't have anymore limitation even for your first query
now, i don't really understand why you use ajax to load the whole data as in this case it would be more suitable to use datatables native progressive enhancement, that to say, load the whole stuff with ci and then apply datatables to the loaded table

but well, nevermind, this should work

have swing[/quote]

Thanks virtualgadjo, this is actually for a work project, and I'm currently at home (it's 11:30PM here at the moment)... But I'll try that in the morning when I get back to work and see what happens. Smile

I'm pretty new to PHP, so I still tend to get confused by things that seem simple and logical to your everyday PHP devs... Smile I'm sure I'll get there one day though.

[eluser]ZaLiTHkA[/eluser]
[quote author="virtualgadjo" date="1343833378"]this function is in the query generate function of the library...
if you don't want any limit to your query just transform it into this
<snip>[/quote]

When I try that, instead of getting all rows back, this is all that gets returned:
Code:
{
  "sEcho":0,
  "iTotalRecords":2849,
  "iTotalDisplayRecords":2849,
  "aaData":[],
  "sColumns":"Store.fk_CompanyID,Store.fk_ProfileID,Store.StoreID,Store.Name,Store.fk_JiraID,Store.IsBetaStore"
}

Isn't there a way to set a query limit in my model? Following the current idea of...
Code:
$this->datatables->select();
$this->datatables->from();
// etc etc
...surely it would make sense to have a method that could be accessed like this:
Code:
$this->datatables->limit();

Which doesn't exist currently.. Or am I missing something? If I'm not missing anything, I think I should probably just write a quick method to provide this functionality.

Edit: Ok, I might have jumped the gun slightly there.. I'm not quite familiar enough with CodeIgniter to go editing/extending functionality like that. However, I did just figure out if I comment out the call to the get_paging() method, then my SQL query runs without any limit (which actually suits this particular project perfectly anyway).

My generate() method now looks like this:
Code:
public function generate($charset = 'UTF-8') {
// $this->get_paging();
$this->get_ordering();
$this->get_filtering();
return $this->produce_output($charset);
}

Problem solved. Smile

[eluser]virtualgadjo[/eluser]
hi,

i haven't tested the function like this, maybe
Code:
if ( isset($iLength) && $iLength != '-1' && $iLength != '' )
would work better
i use it like this
Code:
if ( $iLength != '-1' )
{
    $this->ci->db->limit($iLength != '' ? $iLength : 100, ($iStart)? $iStart : 0);
}
as its original version didn't allow the -1 trick to work with the paging function
but i think if you want to get all your data it's here things must happen

one more thing you may have to check is tou iDisplayLength, by default it's -1 in datatables, may be you could also try
Code:
$iLength = isset($this->ci->input->post('iDisplayLength')) ? $this->ci->input->post('iDisplayLength') : -1;
always in the get_paging function

now, once more, it's a funny idea to get all the data with ajax instead of retreiving them with a simple query in a model and then use datatables on the returned table...

have swing

[eluser]ZaLiTHkA[/eluser]
[quote author="virtualgadjo" date="1343907753"]one more thing you may have to check is tou iDisplayLength, by default it's -1 in datatables, may be you could also try
Code:
$iLength = isset($this->ci->input->post('iDisplayLength')) ? $this->ci->input->post('iDisplayLength') : -1;
always in the get_paging function[/quote]

I don't think that would work for me, my AJAX request is sent as a GET, not a POST. I haven't specified the type though, I'm simply fetching the data with the following:

Code:
$(document).ready(function() {
// Initialse DataTables
var oTable = $('#dataTable').dataTable({
  "oLanguage": {
   "sSearch": "Search all columns:",
   "sLoadingRecords": ""
  },
  "aLengthMenu": [[10,25,50],[10,25,50]],
  "iDisplayLength": 10,
  "sPaginationType": "full_numbers",
  "sAjaxSource": 'main/get_store_list_json',
  "bDeferRender": true,
});
});

I don't quite follow what you mean here though..
[quote author="virtualgadjo" date="1343907753"]now, once more, it's a funny idea to get all the data with ajax instead of retreiving them with a simple query in a model and then use datatables on the returned table...

have swing[/quote]

Having a table search feature is essential with the number of rows I'm working with here, only searching through 100 records at a time seems pretty counter intuitive to me. :/

[eluser]virtualgadjo[/eluser]
first, as long as you have
"iDisplayLength": 10,
in your js, the table will only display... 10 éléments Smile

what i mean about the ajax thing is that, the serverside processing using datatables library is interesting only if you don't want to display all the data as it makes lighter requests
when you want to get all the data at first you don't need ajax nor datatables serverside library, just get all your data with a request in a ci model, put it in the view and then, as you want to take advantage of datatables functionnalities you can just use it without the server sideprocess, in its native progressive enhancement way in fact

have swing




Theme © iAndrew 2016 - Forum software by © MyBB