Changes
Title
unchanged
CGridView keep focus on the control after filtering
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
CGridView, filter
Content
changed
[...]
The first thing to do is register default handlers(filter change and afterAjaxUpdate) and register the cursorEnd function.
You can add filter change event anywhere on the page.
```php
// Default handler for filter change event
$(function(){
$('input,select', '.grid-view tr.filters'Configure all GridViews in the page
$(function(){
setupGridView();
});
// Setup the filter(s) controls
function setupGridView(grid)
{
if(grid==null)
grid = '.grid-view tr.filters';
// Default handler for filter change event
$('input,select', grid).change(function() {
var grid = $(this).closest('.grid-view');
$(document).data(grid.attr('id')+'-lastFocused', this.name);
});
}
);
// Default handler for beforeAjaxUpdate event[...]
fe.focus();
}
// Setup the new filter controls
setupGridView(grid);
}
// Place the cursor at the end of the text field
jQuery.fn.cursorEnd = function()
{
return this.each(function(){[...]