Open AshHimself opened 9 years ago
Can you link to the dataTables documentation on DT_RowId?
Any idea or direction you could point me to fix this myself?
Sorry man I don't really use this anymore, because I don't program on Cake2 applications anymore :-( If you have code you want to commit into this project I can make you a collaborator.
Not a problem at all.. I will look into fixing it and commit. Thanks Chris.
On Thu, Jan 22, 2015 at 12:26 AM, Chris Nizzardini <notifications@github.com
wrote:
Sorry man I don't really use this anymore, because I don't program on Cake2 applications anymore :-( If you have code you want to commit into this project I can make you a collaborator.
Reply to this email directly or view it on GitHub https://github.com/cnizzdotcom/cakephp-datatable/issues/27#issuecomment-70868737 .
@AshHimself Did you manage to make any progress with this?
Hey @jammy-git Looks like dataTables itself only lets you use DT_RowID with a flat array. You can define what field you would like DT_RowID to lookup but only in with the Editor license. My solution was to apply the id to the row using "fnRowCallback". This issue can be close
"fnRowCallback": function(nRow, aData, iDisplayIndex) {
nRow.setAttribute('id',aData.DT_RowId);
},
Thanks for the rapid response!
I came up with a slightly different solution in the end. In getResponse, from line 163:
if($this->mDataProp == true){
if( isset($i[$this->controller->modelClass]) && array_key_exists('id', $i[$this->controller->modelClass]) ) {
$i['DT_RowId'] = $i[$this->controller->modelClass]['id'];
} elseif( array_key_exists('id', $i) ) {
$i['DT_RowId'] = $i['id'];
}
$response['aaData'][] = $i;
}
Fantastic, I'll defiantly give your code a test when I get home as this will save me from having to define the callback in each DataTable!
No problem.
Obviously it's not very flexible as it forces the use of the 'id' field for the Model to be the DT_RowId, but I figure in 99% of use cases that's what you'd want anyway.
I'm using DataTables 1.9.4 and Editor 1.2.4 and it seems to work OK - the editor passes the correct id through via the Create and Edit AJAX calls at least.
I think the best way to do this would be to specify a "dtRowIdField" as a property of the DataTableComponent, then have the component alter the conditions of the query and have the DB return DT_RowId as part of the query results. Think that would be slightly less overhead than altering $response in a loop - especially for larger datasets!
And after all that, I go back and look at the documentation this morning and find the idSrc property!
I was just about to tell you that :) Sadly, its only available in the editor plugin.
Is it possible to implement the datatables option DT_RowId with cakephp-datatable?
The only way I was able to get it to work was to add the following code to the component. Though the side effect for this was that linkable then no longer worked.
Added to the getResponse function; $removeName = Configure::read('current_controller'); $removeName = rtrim($removeName, "s"); $response = Set::extract('/' . $removeName . '/.', $response);
Datatables documentation as follows; http://datatables.net/release-datatables/examples/server_side/ids.html