Change filter value from code
Change filter value from code
Hi everybody,
I changed the input text box functionallity to filter only after press the enter key and I've been trying to clear the value of the text box after this. I did it with something like this code:
[code]
$('#example input').bind('keyup',function(e){
if (e.keyCode == 13)
{
oTable.fnFilter(this.value);
this.value = "";
}
});
[/code]
But this code doesn't work...If I use another filter in the table then the input text filter will have the previous value unless I first press enter with a empty value. Has Anybody got something like this?
Cheers,
Pawel.
I changed the input text box functionallity to filter only after press the enter key and I've been trying to clear the value of the text box after this. I did it with something like this code:
[code]
$('#example input').bind('keyup',function(e){
if (e.keyCode == 13)
{
oTable.fnFilter(this.value);
this.value = "";
}
});
[/code]
But this code doesn't work...If I use another filter in the table then the input text filter will have the previous value unless I first press enter with a empty value. Has Anybody got something like this?
Cheers,
Pawel.
This discussion has been closed.
Replies
Allan
Thanks for replying soon. I'm gonna try explain better my problem.
In addition to the input text filter I'm using two columns filters. My Idea is if the user press enter with some value that wants to search in the table then he will get the results and will be able to select differents pages in the table, filtered with the search value. In this situation if the user wants to filter the table with one of the columns filters then the search value will be cleared and will not affect to the table filter so he will not have to clear the input text, filter like this and then use another filter.
Do you understand better what I mean?
Cheers,
Pawel.
Allan
Thanks for your time.
Cheers,
Pawel.
I'm sorry but yesterday I didn't try so much the code and I've just realized I'm still having a problem. I don´t know what I have to use to set the value of a filter from code, I mean, yesterday I tried with this code:
[code]
$("#example_filter input").bind('keypress', function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13) {
e.preventDefault();
oTable.fnFilter(this.value);
$("#example_filter input").val('');
}
});
[/code]
This code clears the value of the text box but the filter still has the previous value, what am I doing wrong?
Cheers,
Pawel.
The sector you have will only match one element. Bare in mind that you can't have duplicate IDs in an HTML document, so DataTables only applies an ID to the first instance of a control (example_filter for example).
Allan
Thanks for replying. I tried with that and it works fine, cheers !
Regards,
Pawel.