i am displaying set of records using cgridview and i have given sorting for each coloumn available in grid. [size="2"]The sorting works fine with Ajax. [/size]
now i have a search field, which takes the date as a input and filter the cgrdview data records.
assume now i am having the filtered data’s in grid view and sorting them. what happens is, [color="#8b0000"] the sorting works but my data set in gridview is rested to normal which will now list all the data records without any filter…[/color]
in other words,
in my gridview i have [color="#8b0000"]100 records[/color] by default. now i am sorting them and they work fine with all sorting ways.
now i am applying a filter by giving a created data which i expect data to be shown on that date. so the filter applies correctly and my data records are as appropriate. now have only [color="#8b0000"]20 records[/color] which is expected.
now i am sorting again… what happens is, sorting happens but i get back all the records ([color="#8b0000"]100 records[/color]).
why does this happens ? can somebody help me out to fix this. i am quiet running out of time.
It won’t happen if you use gridview native filter inputs.
By looking at jquery.yiigridview.js you can see that inputSelector just take data from gridview’s filters so if you use your own inputs, after filtering or sorting by gridview’s internal functionality you will lose your filters , to solve it you have some options:
first option is to keep your own filters and use it on further actions.(for example you can keep your model in a session variable)
second an in my opinion a better option is to extend gridview and customize it’s inputSelector in js file to recognize your own filter inputs as gridview’s internal filter inputs
I looped around the post array and assigned them into a session if they are set.
/*
* To set all attributes in model
* Note: getAttributes() method doesnt support for additional variables
* created in model.
*
* @param post array $data
*/
public function setStateAllAttributes($data) {
$attrState = array();
foreach ($data as $key=> $value) {
if (!empty($value))
$attrState[$key] = $value;
}
Yii::app()->user->setState('searchFields', $attrState);
}