tags:

views:

89

answers:

2

in the index.ctp, i can get view all the details of data for my customer table. I wan to have a function which let user to select view by company, when user select the company, i use javascript to get know the company id, but i got no idea how to sort the data view by the company id..

i wanted to just list out the data in the index.ctp when the user selected the company for view, all the data will have their own company, which just few company are provided. any idea to create this action?? by refreshing page and i get view the new list of data in index.ctp. thanks.

i am new to cakephp.

+1  A: 

If you use pagination, you will be able to easily allow the user to sort the data. By default the data is sorted on the server (at datasource level), so the page will reload when a sort link is clicked.

<?php echo $paginator->sort('Company', 'company'); ?>

If you want a more dynamic experience using JavaScript, this is also possible using pagination, but more code is required. There is information on AJAX pagination in the manual as well as an article about advanced pagination on the Bakery.

If this isn't what you are looking for, can you please clarify?

deizel
A: 

If what you really want is to filter (not sort) your data, you can do it with the paginate method/vars of the controller too:

   $this->Model->recursive = 0;
   $data = $this->paginate('Model', array('OR' => array(array('Model.type' => 1), array('Model.subtype LIKE' => '%SOMETHING%'))));
   $this->set('data', $data);

This would create a query like this:

   WHERE ((`Model`.`type` = 1) OR (`Model`.`subtype` LIKE '%SOMETHING%')

You can also pass conditions, sorting and all that straight to paginate() from the controller like so:

   $this->paginate['conditions'] = array('Recipe.title LIKE' => 'a%');
   $this->paginate['limit'] = 10;

Pagination, Controller Setup

Eduardo Romero