0
votes

i would like to search a TbGridview rendered by ajax call in Yii v1.

i am not able to achieve the functionality using an instance of Csort also.

the complete scenario:

user types in an autocomplete and search based on employee id or name.. i fetch the some details of employee from another history table based on his employee id

i would like to perform sort and paginate in the same grid but it fails on clicking sort of the column header i am redirected to my ajax search function and since the autocomplete is not being done i am not able to pass the user id to the function..

PS: please note: i am not using a model to display the gridview

in my controller action:

     $gridDataProvider = new CArrayDataProvider($cap_detail);
        //$this->print_data($gridDataProvider);
        $gridColumns = array(
            array('name'=>'reason_desc', 'header'=>'Reason Description'),
            array('name'=>'filed_by_name', 'header'=>'Filed By', 'htmlOptions' => array('style'=>'width:20%')),
            array('name'=>'filled_date', 'header'=>'Filed Date', 'htmlOptions' => array('style'=>'width:10%')),
        );

in my ajax page view:

$this->widget(
        'bootstrap.widgets.TbGridView',
        array(
            'dataProvider' => $gridDataProvider,
            'template' => "{items}",
            'columns' => $gridColumns,
        )
    );

Possible duplicate of what i am trying to achieve: Yii: Client-side sorting & pagination with CGridView and CArrayDataProvider

1

1 Answers

1
votes

Ok I have used datatables for the task on another page, ditching cgridview and it looks so much better with bootstrap 2...

regarding my question above, i have done the following:

  1. add javascript onclick event listener to the sort link i.e for class .sort-links of cgridview

  2. call the ajax function and reload the grid with new sort order

works perfectly