Filter search via button click...across numerous datatables
Filter search via button click...across numerous datatables
Hello folks,
First off, a big round of applause from me to Allan for a magnificent plugin. It's helped make my project simpler. Thanks man.
I tweaked the plugin a bit by adding a new feature called "customFilter". It has a value of 1 or 0. If it's 0, it basically displays the default filter textfield. If it's 1, it replaces the default with a custom filter and a button. This way, I can decide when I want the filter to be fired dynamically or through a button click.
By default, I have set the value to 1 in the plugin itself so all my pages display the custom filter. However, I have come across a massive problem.
As you may have guessed, I can initiate the filtering by binding this command to the button.
[code]
tableobj = (table_id).datatable();
[/code]
[code]
$(custom_button_id).click(function() {
tableobj.fnFilter(custom_text_id.val());
});
[/code]
The problem is I have dozens of php files that have different table ids. My instructions are to not add the code above to all the phps.
You may have guessed my requirement by now. Rather than write this function in each php file, I wish to change this to a generic code within the plugin that can grab the table Id, instantiate the datatable and perform the filtering. How do I do this?
I appreciate any kind of advice. Thanks for helping me out.
Regards,
Sabier
First off, a big round of applause from me to Allan for a magnificent plugin. It's helped make my project simpler. Thanks man.
I tweaked the plugin a bit by adding a new feature called "customFilter". It has a value of 1 or 0. If it's 0, it basically displays the default filter textfield. If it's 1, it replaces the default with a custom filter and a button. This way, I can decide when I want the filter to be fired dynamically or through a button click.
By default, I have set the value to 1 in the plugin itself so all my pages display the custom filter. However, I have come across a massive problem.
As you may have guessed, I can initiate the filtering by binding this command to the button.
[code]
tableobj = (table_id).datatable();
[/code]
[code]
$(custom_button_id).click(function() {
tableobj.fnFilter(custom_text_id.val());
});
[/code]
The problem is I have dozens of php files that have different table ids. My instructions are to not add the code above to all the phps.
You may have guessed my requirement by now. Rather than write this function in each php file, I wish to change this to a generic code within the plugin that can grab the table Id, instantiate the datatable and perform the filtering. How do I do this?
I appreciate any kind of advice. Thanks for helping me out.
Regards,
Sabier
This discussion has been closed.
Replies
Which variable in the plugin stores the object "tableobj"? If that can be accessed directly in the js, I can simply write the code above in the plugin itself and not worry about accessing the table ID directly.
To add a class right now is to change the files anyways which is a big no-no. What I seek is simpler.
Somewhere in datatables.js is a variable that holds the table object i.e tableobj (see code above)
All I need is access to that object so I can directly write the following in the js itself.
[code]
$(custom_button_id).click(function() {
tableobj.fnFilter(custom_text_id.val());
});
[/code]
That way I don't have to worry about grabbing the ID. If such a thing is possible, I'd be much obliged. Thanks.
[code]
$("div.dataTables_wrapper table")....
[/code]
I don't know whether Allan agrees this :)
Allan
Initializing the table is not a problem at all. The trouble is I am supporting an application written by someone else and he initialized it in each php. I was hoping I could resolve it in the js itself by just accessing the object directly. Oh well, guess I gotta do it the hard way.
But thanks to both of you for clearing it up.
Regards,
Sabier