Closed jaganreddy closed 11 years ago
Put it inside $this->DataTable->settings['Avatar']
Thanks tigrang, but still i am not getting data with conditions.
in my controller
public $components = array('DataTable.DataTable'=> array( 'columns' => array( 'id' => 'Id', 'name' => 'Name', 'inactive' => 'Status', 'created' => 'Created', 'Actions' => null, ) ));
in index action public function index() { $this->DataTable->settings['Avatar']; $this->paginate['Avatar'] = array('conditions' => array('Avatar.id' => 1),); }
in view
bProcessing:true, bServerSide:true, sAjaxSource:"/avatars/?model=Avatar"
If i not added model=Avatar, i am getting exception 'DateTableComponent: Model not specified for request.'
When i look into the DataTableComponent file at line number 130 to 134, it is looks like model parameter in mandatory and the parameter model is passing into process() method. In process() method, gathering information is missing.
I also faced problem to getting data with multiple model with join. Could you provide me simple example
Thanks again
Yes a model is required in the url. I meant $this->DataTable->settings['Avatar'] = array('conditions' => array('Avatar.id' => 1),);
Thanks a lot tigrang, its working.
Before this change i tried by replacing files component and helper file with older version, it is also working.
Now i changed with new version.
Thanks again.
I have a requirement to handle multiple models with multiple actions with in single controller.
public function index() { $this->DataTable->settings['Avatar']; $this->paginate['Avatar'] = array('conditions' => array('Avatar.id' => 1),); }
public function admin_index() { $this->DataTable->settings['SuperAvatar']; $this->paginate['SuperAvatar'] = array('conditions' => array('SuperAvatar.id' => 1),); }
For the above actions how can I define columns in controller component initialization ie at
public $components = array('DataTable.DataTable'=> array(....
$this->components = array('DataTable.DataTable' => array('Model1' => array('columns' => ...), 'Model2' => array('columns' => ...)));
Its working great. Thanks a lot for your helping.
Can you please explain what is the $scope parameter for?
I want to get total count with conditions. every time the table is loading the $total is getting all the records from the table. eg(Showing 1 to 1 of 1 entries (filtered from 4 total entries)). Total entries should also fetch depends on the condition.
On declaring as below search is not working $this->components = array('DataTable.DataTable' => array('Model1' => array('columns' => ...), 'Model2' => array('columns' => ...)));
$this->components=array('DataTable.DataTable' => array('Avatar'=>array('columns'=>array('name'=>'Name', created=>'created')),'SuperAvatar'=>array('columns'=>array('superadmin'=>'Name','adminname'=>'admin')......
With the above initialization sorting and searching not working.
Not working is never helpful. What errors are you getting? Check with firebug or chrome developer tools for the result of the ajax request.
There are no errors with ajax request. Following request and output is generating when i click on column heading for sort
Respnse {"iTotalRecords":0,"iTotalDisplayRecords":2,"sEcho":8,"aaData":[["1","<a href=\"\/avatars\/view\/1\">Admin<\/a>","Active","11-28-2012 06:50PM","<\/a>"],["2","<a href=\"\/avatars\/view\/2\">User<\/a>","Active","11-28-2012 06:50PM","<\/a>"]]}
Thanks for your reply
Do you get an error from the jquery lib? You have only 2 columns configured array('Avatar'=>array('columns'=>array('name'=>'Name', created=>'created')),
but in the response I see 5. I think that mismatch can cause an issue? If you aren't getting any errors, then I dont know because you are getting results back. The only other thing I see is that ITotalRecord = 0 but iTotalDisplayRecords is 2. I'll get back to you on that.
I am statically assigning ITotalRecord=0 for other reason. But my main problem is sorting and searching. My configuration in Controller. I am hiding 'id' column in front end. 'DataTable.DataTable'=> array('Avatar'=>array( 'columns' => array('id', 'name', 'inactive', 'created', 'Actions' => null), 'triggerAction' => array('index')), 'Zavatar'=>array( 'columns' => array('id', 'name', 'inactive', 'created', 'Actions' => null), 'triggerAction' => array('admin_index'))
Um..ok. What exactly is the issue with sorting and searching? You click a header and it doesn't change?
while clicking on header doesn't changing and while searching by entering text in search box also not changing results
It's working for me. I dont know sorry. You can try putting in debug statements see what's going on. Grab the latest master and try that, too.
ok. I will try with debug and also with latest master. Let you know if I found any information.
Thanks for the help and your time.
It is working when I remove the condition statement in index()
Not working when code as follow public function index() { $this->DataTable->settings['Avatar'] = array('conditions' => array('Avatar.org_id' => $this->Session->read('UserAuth.User.org_id'))); }
It is working when I comment above code.
When I debug in DataTableComponent file _parseSettings() method $settings['columns'] are fetching empty. So, code not executing in foreach($settings['columns'] as $field => $options) {
The main requirement for me is, the default table data of avatars should always fetch with in a organization. So I want to add a mandatory condition for datatable.
Is there any otherway to set default condition.
Thanks
Whats the output of debug($this->Session->read('UserAuth.User.org_id'))
are you sure that's set? Do me a favor and paste your controller on gist or any other code sharing site.
Edit: I am blind - sorry it's late. You are overriding the 'Avatar' key by doing that. Change it to this:
$this->DataTable->settings['Avatar']['conditions'] = array('Avatar.org_id' => $this->Session->read('UserAuth.User.org_id'));
Otherwise you're overwriting the columns and other config values set in $components
Althought I think what you are after is $this->DataTable->settings['Avatar']['scope'] = array('Avatar.org_id' => $this->Session->read('UserAuth.User.org_id'));
Note: scope
option may be bugged in the latest master. I'll have a fix for it soon.
Oh, its working great. You made my day, Today is my delivery of my first phase.
Thanks a lot tigrang
No problem. Thanks for using the plugin :)
conditions in action method not executing. public function index() { $this->paginate['Avatar'] = array( 'conditions' => array('Avatar.id' => '3'), ); }
Results are also fetching when I comment code in index action.
Is it mandatory to pass a model paramer in ajax request? ex: /avatars?model=Avatar
when i remove model parameter the data is not loading