Closed jansley closed 11 years ago
Thanks for letting me know. The issue isn't that you need to pass by reference, but you need to return $conditions in your custom search methods. I'll update that when I can, or feel free to send a pull request :)
Thanks for your prompt reply!
I would like to add some extra data to returned json . I think off using the before filter callback ta add these data to the dtResults var. Is it the way to go or is the somme feature in your plugin I can use for this.
What type of data?
You can set extra view vars from the controller and in your view have:
$this->set('myViewVar', 'some_data');
$this->dtResponse['extraField'] = $myViewVar;
You can conditionally set the view var by checking if it is a data table request by:
if ($this->DataTable->isDataTableRequest()) { /* set view var */ }
Thank you
I have an other problem now!
I would like to use post instead of get . With GET I have the expected results but with POST i have some cake errors in the json response . This the datatable settings iI use
iTable1 = $('#ListeUser').dataTable({
//ajax get
sAjaxSource: '<?php echo $this->Html->url(array("controller"=>"ctl_transactions" ,"action" => "etat", "?" => array("model" => "CtlTransaction"))); ?>',
//ajax POST
//sAjaxSource: '<?php echo $this->Html->url(array("controller"=>"ctl_transactions" ,"action" => "etat")); ?>',
sPaginationType: 'full_numbers',
bProcessing: true,
bServerSide: true,
sDom: '<"dataTables_wrapper"it>rt<"bottom"p><"clear">' ,
//sServerMethod: "POST",
//bStateSave: true ,
"oLanguage": {
"sUrl": "../js/media/Trsfx.txt"
},
aoColumnDefs: [
{ "bSearchable": false ,"aTargets": [ 0 ],"bSortable":false ,"bVisible": true,},
{ "bSearchable": false, "aTargets": [ 1 ] },
{ "bSearchable": false, "aTargets": [ 2 ] },
//{ "bSearchable": false, "aTargets": [ 3 ] },
{ "bSearchable": true, "aTargets": [ 2] },
{ "bSearchable": false, "bVisible": true, "aTargets": [ 5] },
{ "bSearchable": false, "bVisible": true, "aTargets": [ 6] },
],
"fnServerData": function ( sSource, aoData, fnCallback ) {
alert("gdgdgd");
$.ajax( {
"dataType": 'json',
"type": "POST", //replaced by GET when using get
"url": sSource,
"data": aoData,
"success": function(json){
alert("Test success");
// $('#processingTime').html(json.iProcessingTime); // iProcessingTime is the variable that we added in JSON at the server side
fnCallback(json);},
//"success": fnCallback,
"timeout": 15000, // optional if you want to handle timeouts (which you should)
"error": TraiterAjaxError // this sets up jQuery to give me errors
} );
},
//"aoSearchCols": [
//null,
//null,
//null,
//null,
//{"sSearch": '0'},//,"bEscapeRegex":true
//null,
//null
//],
"aaSorting": [ [ 0, "desc"] ] })
Error response:
Notice (8): Undefined index: renderer [CORE\Cake\Error\ErrorHandler.php, line 119]
Do you happen to have the security component enabled?
no it's not enabled
Looks like your config file is missing a field for your error handler. Look at the config file in the app folder from the cake git repo to get the correct default value.
In others cake projects I have this error when I make a call to an action /controller that does not exist
Open app/Config/core.PHP and find the part that looks similar to this:
Configure::write('Exception', array( 'handler' => 'ErrorHandler::handleException', 'renderer' => 'ExceptionRenderer', 'log' => true ));
Make sure you have the renderer part. If you don't add it then you'll be able to see what the real error is.
thank you!
after inserting your code I have the real error as you said
{"name":"DateTableComponent: Model not specified for request.","message":"\/olb\/IcbsTransactions\/etat"}
Make sure you have $this->DataTable->paginate = array('CtlTransaction');
in your controller and that you have ?model=YourModel
in your sAjaxSource
.
It has not worked with ?model=CtlTransaction . SO I tried with aoData.push({"name":"model","value":"CtlTransaction"}); without ?model=CtlTransaction
My code: "fnServerData": function ( sSource, aoData, fnCallback ) { aoData.push({"name":"model","value":"CtlTransaction"}); $.ajax( { "dataType": 'json', "type": "POST", "url": sSource, "data": aoData, "success":function(json){ //Process of json Extra data fnCallback(json);}, ....
Thank you !
Tigrang , you have made a great job ! Thanks for this plugin!
$conditions parameter should be &$conditions in custom search function to be taken in account.
<?php class Users extends AppModel { public function customSearch($field, $searchTerm, $columnSearchTerm, $conditions) { if ($searchTerm) { $conditions[] = array("$field LIKE" => '%' . $searchTerm); // only do left search } if ($columnSearchTerm) { $conditions[] = array($field => $columnSearchTerm); // only do exact match } } }
Ansley