Hey guys,
Sorry I’ve been asking so many questions. I’m using the CGridView widget. I’ve set up filters, and I’ve set up an onKeyUp jquery function to update the table when a user types into a filter element. I’ve also set up the view to return only the table element on an ajax request, instead of the whole page.
The problem is, once the user types into the element and the delay passes, the whole table is redrawn. The focus is taken away from the input element. How can I get the cursor to remain in the input field after the table as updated with new, filtered information? Or a better question, how can I get the table to only update the rows, instead of the whole element - table headers and all?
I’m using the onkeyup suggestion from here:
Yii forum
I have attached seemingly relevant pieces:
Yii::app()->clientScript->registerScript('search', "
function refreshList() {
$.fn.yiiGridView.update('" . $grid_id . "', {
data: $('tr.filters input').serialize()
});
}
var timeoutHandle;
$('#content').on('keyup', 'tr.filters input', function() {
clearTimeout(timeoutHandle);
timeoutHandle = setTimeout(function() {refreshList()}, 300);
});
"
);
And the partial view:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => $grid_id,
'dataProvider'=>$model->search(),
'columns' => array(
array(
'class' => 'CButtonColumn',
'template' => '{view} {update} {delete} {view_classes} {add_class}',
'viewButtonUrl' => 'Yii::app()->controller->createUrl("view", array("id" => $data->id))',
'updateButtonUrl'=> 'Yii::app()->controller->createUrl("update", array("id" => $data->id))',
'deleteButtonUrl'=> 'Yii::app()->controller->createUrl("delete", array("id" => $data->id))',
'buttons' => array(
'add_class' => array(
'label' => 'Add Class',
'url' => 'Yii::app()->createUrl("registeredClass/create", array("student_id" => $data->id))',
),
'view_classes' => array(
'label' => 'View Classes',
'url' => 'Yii::app()->createUrl("registeredClass/view", array("student_id" => $data->id))',
)
)
),
'first_name',
'last_name',
),
'filter' => $model,
));