ColumnControl searchList not updating when table data changes
ColumnControl searchList not updating when table data changes

I have a table that uses the ColumnControl searchList. When data is added, updated or removed from the table the search list contents aren't updating. In this example if you add a new entry with unique field values and check the search list dropdowns the new values don't appear.
https://live.datatables.net/dufeciyo/1/edit
Is there a way to get them to stay in sync with the data in the table?
Thanks.
Ben
This question has an accepted answers - jump to answer
Answers
Hi Ben,
For local table editing, there actually isn't at the moment. Apologies that is an oversight on my part and I've made a note to add an API method to do that.
Currently, if the options are coming from Ajax, then they will be refreshed on each Ajax reload.
Allan
Allan,
I have tables that are being updated automatically (polling for updates from the server) and also tables that are updated when the user uses the editor to add/update/delete data and those use the editor's ajax option. Neither one's ColumnControl searchList is updating when the table data updates. Is it not an option to have the ColumnControl searchList to listen for change events for the table's data and then update appropriately? Or am I missing something?
The reason I used the editor local data example is I don't know how to set up a live.datatables.net example with ajax calls to the server (that's what you're referring to, right?). Is that possible? I'd very much like to see a working example of this functionality to play around with and hopefully figure out what I'm doing wrong.
As an aside, I don't know if this would be feasible but it would be really cool if each one of the DataTables and Editor example pages had a link to automatically create a live.datatables.net page with all the appropriate plugins already included and the code from the example loaded in as well. It would be really handy for quickly creating working and reliable demos to submit with tickets as well as a place to play with live examples to experiment. Just a thought.
Thanks.
Ben
There is no such event at the moment. It should be looking for new options on each Ajax request (source code), and if that isn't working I'd welcome a test case showing the problem.
There does need to be a new API that will trigger a refresh of the options though and that will be added for 1.1 I expect.
Unfortunately at the moment the live site doesn't have the option of interfacing with a backend for Editor.
I have pondered that in the past, but there always seems to be something more pressing to do! I think it is a neat idea.
Allan
Allan,
Thanks for the link to the code. I'll check to make sure it's getting run. If that's not the issue I'm happy to put together a test case to share. That said, if live.datatables.net doesn't support ajax calls to the server how do I put together a test case if that's the setup where this should work (as opposed to standalone as I set up in the initial example)? I feel like I'm missing something.
Thanks.
Ben
See this technote for options to use
ajax
loaded data. Maybe one of those will work for a test case.Kevin
Kevin,
Thanks for the tip. I tried to convert the standalone editor example over to use ajax.
https://live.datatables.net/kihiwava/1/edit
It loads the data but the editor portion is no longer working so I can't add/update/delete records. The editor buttons are still clickable but anything I do with them just vanishes (and the edit button doesn't actually load the row data). I had to remove the columns section of the datatable definition to get the ajax data to load - not sure if that's related. Am I missing a step?
Thanks.
Ben
Sorry I did miss the Editor discussion you and Allan had. Based on my understanding ColumnControl will only update with the Datatables
ajax
responses (likeajax.reload()
I think) and not the Editorajax
used during edits.Your test case has server side processing enabled. Is that what you are using in your solution? If so see the ColumnControl Server Side Processing docs.
If you are not using server side processing then on option might be to use
ajax.reload()
insubmitSuccess
orsubmitComplete
. However this might be too much network data.Another possibility is to refactor the custom API plugin created in this thread. I haven't dug into it but it might be possible to change the plugin to support and array of column indexes, loop through the column indexes and get the unique sorted column data, similar to this example, and update the options. Call this in
submitSuccess
instead ofajax.reload()
.Allan's implementation of a new API for this might be different.
Kevin
Kevin,
No worries. No, we're not using server side processing. Honestly I was just trying to find an example from the tech notes page that you linked to that I could clone and rework so it has both the Editor and the ColumnControl on it so I could see it work, compare it to I'm doing in our app, experiment with it and link to it to submit as a test case if appropriate. It's starting to sound like the better option would be to put a pin in it and wait for the 1.1 changes Allan mentioned that will add a way to trigger an update that will refresh the options lists.
I was picturing the options list automatically listening for a table update event so it could keep in sync behind the scenes but Allan said that event doesn't exist right now. Not sure if tying the 1.1 api addition to the 'draw' event would be a bad idea but presumably that would get the job done, though it might be a bigger hammer than is appropriate. I'm guessing ideally you'd want something more like an event for rows added/updated/deleted but without that I could experiment with tying it to the 'draw' on my end and see what happens, once it's available.
I just finished updating our app from DataTables 1.x to 2.x and one of the things that didn't work any more was custom column filters that I'd built that handed this functionality. Pretty happy to be rid of all that custom code and use ColumnControl instead and this is one of the last pieces I'd like to get working but it's not an emergency.
Thanks.
Ben
Oh boy, I started looking at the API plugin and its for SearchPanes not ColumnControl
I've been confused all day. Nevermind my above comments. Probably best to wait for 1.1.
Kevin
Here is a starter example:
https://live.datatables.net/himazura/1/edit
As noted above the edits can't be stored at the server so there is no Editor
ajax
option. It may or may not be useful for you to mess with other things.Kevin
I'm working on Editor 2.5 at the moment, and ColumnControl 1.1 is going to go hand-in-hand with that (to add server-side processing support to CC). So it should be sometime next month I add them
.
Allan
Allan,
Sounds great! Thanks!
Ben