Hi Charles,
These are good suggestions. All of them! Let me go through them one by one.
Q1) Great idea! Although I don’t think this can be implemented with a query string as the request is sent by the jQuery DataTables object. We need to add a query input field for every queryable column. I found a great solution here: https://stackoverflow.com/questions/48316191/jquery-datatables-set-default-search-value-for-a-column-when-initializing-a-tab
I think the last suggestion is what you need. The one rates as -2 ;-)! Can you check the example?
I added your request to my to do list. I’ll let know when it is available.
Q2) You can use column “Table options (advanced)” in the Data Publisher to add an initial search value. There are two ways to do this:
(1) {“processing”:false,”stateSave”:false,”search”: {“search”: “godwin”}}
(2) {“serverSide”:false,”processing”:false,”stateSave”:false,”searchCols”:[{“search”:”godwin”},null,null]}
The first option adds a global search. The user will see the search value in the search box. The search value can be change by the user.
The second option adds a column specific search value. In this example the search value will be used for the first column only. You can add multiple search values. These search values cannot be change by the user and would the same as adding a default where. In combination with the solutions I mentioned below Q1 however, this is giving you the possibility to let a user search on individual columns. Make sure that the number of columns in your options matches the number of columns selected in your publication. You can use the links below for more information about these options.
https://datatables.net/reference/option/search
https://datatables.net/reference/option/searchCols
(Q3) I’ve planned to add more features to this area this year. I will keep you posted.
Two final notes:
NOTE1) If you want to experiment with Q2 option 2, you’ll need to update your plugin version. I had to patch the current release (2.7.3) to fix the serverSide=false request. Make sure you don’t delete all plugin tables and options (manage plugin > uninstall settings) if you need to remove the plugin first. Otherwise you will lose all your settings (including projects, publications, and so on).
NOTE2) This month I will release version 3 which supports remote database access! Just wanted to mention as I know you’re waiting for that feature… 😉
Thank you for all your wonderful feature requests!
Best regards,
Peter
I don’t know if this is a 4 or a variation on 1 and 2.
It would really be nice to open a page with a dynamic search value preloaded. The value I have in mind is dynamic. It could be implemented as either a query string or a value in session data. For example if a user filled in a form with a name of “jones” and pressed Submit and the data table page would open with a search of Jones.
Another application is the front end table maintenance in Data Project. Currently, if a user uses search to find some records, selects one to edit, completes the update and then presses Back to List the search is gone and must be repeated. The Back button works but gets a refresh message, at least in chrome. Dynamically loading or retaining the search value in this case would be very user friendly.
Thaks, keep up the good work.
Hi Charles,
Just wanted to let you know that version 3 is out and allows you to add your own search logic through a shortcode. More info can be found here:
https://wpdataaccess.com/2020/01/29/filter-wpda-construct-where-clause-to-add-custom-search-behaviour/
Let me know if you need help.
Best regards,
Peter
Thanks Peter. Keep up the good work.
The link provided points to the custom where clause topic but does not cover “add your own search logic through a shortcode”
Second question:
Have made a decision on if or when for Q3?
I am planning to experiment with your original answer for Q2 now that I have time.
This is probably a dumb question but JavaScript is not one of my strong languages – yet.
I did some research into Q2 and column filter
I read this page https://datatables.net/reference/api/columns().search()
And the second example is what I want to test. Of course the example uses #example and I need to replace it with the proper id for my published table.
the table i’m publishing is named library_public. There are, in the generate WP page ids starting with library_public1. I’ve tried every iteration if #library_public1… I can think of but fail.
I’m sure I’m missing something obvious, but what?
thanks to all in advance.
Hi Charles,
Is this page online? Maybe I can help if I can have a look at it…
Thanks,
Peter
Any luck. Does column search need any server side work? or..?
Hi Charles,
There is an example on the jQuery DataTables website:
https://datatables.net/examples/api/multi_filter.html
This example works client side. The plugin performs all queries server side. I think your right and it does require server side work to handle those specific queryable columns.
Best regards,
Peter
If it’s server side work, it looks like it will be non-trivial. Should I consider this a great learning experience or can you point me in the right direction? Thanks
I’ll have a look at it and let you know! 🙂
Best regards,
Peter