I need to put the focus on the filter input field after datatable is drawn. I'll try several notations, like [code]$("#mytablename_filter:input").focus();[/code]but nothing works. Can someone give me a hint, please?
...yeah, sorry, I wrote '#mytablename' but I know, it must be the ID.
That was not the point:
[code]$("#mytableid_filter input").focus();[/code]
works well, as long as not another language is in use.
[code]
$(document).ready(function() {
$('#mytableid').dataTable( {
"oLanguage": {"sUrl": "de_DE.txt"},
"sAjaxSource": "myajax.php"
} );
$("#mytableid_filter input").focus();
});
[/code]
does not work (in my case).
de_DE.txt:
[code]
...
"sSearch": "Filter",
...
[/code]
If you want to do it with another language loaded by XHR, you'd need to do it with fnInitComplete ( http://datatables.net/usage/callbacks#fnInitComplete ). The reason for this is that the DataTables initialisation call will complete before the Ajax data has loaded (it's asynchronous...) so DataTables won't have drawn the lanauge or the filter at that time. fnInitComplete is provided for exactly this reason.
Replies
no ideas?
[code]
$("#mytableid_filter input").focus();
[/code]
Do that after DataTables has been initialised and it should work okay.
Allan
That was not the point:
[code]$("#mytableid_filter input").focus();[/code]
works well, as long as not another language is in use.
[code]
$(document).ready(function() {
$('#mytableid').dataTable( {
"oLanguage": {"sUrl": "de_DE.txt"},
"sAjaxSource": "myajax.php"
} );
$("#mytableid_filter input").focus();
});
[/code]
does not work (in my case).
de_DE.txt:
[code]
...
"sSearch": "Filter",
...
[/code]
Allan
[code]...
"fnInitComplete": function() {
$("#mytableid_filter input").focus();
}
...[/code]
works fine with with German language.