ColumnControl: Sending search values with ajax
ColumnControl: Sending search values with ajax

I've just come across the ColumnControl extension, which looks great and ticks a lot of boxes for a project that I'm working on. However, I notice that server-side processing will only be available some time in the future and its something I would very much like to utilise now.
In the meantime, I was wondering if I could use the preXhr event and "intercept" the selected items from a ColumnControl searchList and then add those items to the ajax payload? What I would like to know, is there functionality to get the selected items only for a column that uses a searchList? Thanks in advanve for any guidance on this.
Answers
Yes, you could use
preXhr
to add the extra information - you'd need to query the DOM for it though, there isn't an API to get that information at the moment.I actually think adding server-side parameter sending to ColumnControl will be fairly easy to do (it would be easier than hacking it in with
preXhr
I think). The bit that will take me a bit of time is adding support for it to the server-side libraries I publish.Allan
Many thanks for the quick response - I will certainly query the DOM, just wasn't sure if there was a method already out there that I hadn't come across.
I've got a deadline of a couple of weeks for my project so I will give preXhr a go, initial tests look promising, and look forward to your future updates on this extension. Keep up the great work :-)
Tim
Following on from this, when querying the DOM for each column dropdown with the class 'dtcc-dropdown' - is there a way to relate that dropdown to the column name itself? So that I know what field the search should be on for that column?
@allan ... it looks like the dropdowns are created dynamically when the dropdown icon is clicked - so querying the DOM isn't really possible? I guess the selected values are being stored somewhere as it knows what's been selected when you switch from one dropdown to another for each column.
It looks like you can use
state()
to get the searchList search terms. Go to the Basic search list example and perform one or more searches. In the console paste this:There is a
columnControl
object. This example output is after searching forAccountant
andChief Executive Officer (CEO)
:Whether this changes over time or not I don't know. It may work for you for now until Allan creates some API's.
Kevin
That's a very clever idea Kevin! Nice one! I have no expectation of changing the state structure.
Allan
Thanks very much for this @kthorngren - it's almost there, the only thing is when I use that in conjuction with preXhr the items in searchList are one step behind what has been selected. Not sure if there's any way around that? Perhaps there are some methods I can use on the state object?
@kthorngren - seems my problem can be fixed in preXhr with a call to .state.save() before getting the state so now its in sync. This is looking good! Thanks again, really appreciate you looking into this.
After all these years I didn't realize Datatables saved the state in memory without the use of
stateSave
. Noticed in the searchList init code that it looks like the state is interrogated to grab the searchList for the column when the element is displayed::Glad you got it worked out.
Kevin
What should be happening is that when
state()
is called it will return the current state, not the last saved state. So it sounds like there might be a bug there. I'll look into that.As Kevin says, good to hear you have a workaround.
Allan