restrict search results using server-side search processing
restrict search results using server-side search processing
rldean1
Posts: 141Questions: 66Answers: 1
OH MY GOD! I actually got server-side search working with a MS SQL stored procedure!!!! Pretty snazzy!!
So, a couple of questions:
- Is there a way to stop "all" records from being returned when the webapp is opened? "All" results are returned on init, which I assume is because the search filter is literally blank.... in other words, unfiltered.
- Is there a way to better control what happens during a global search in the DT search bar? For example, typing 1 letter searches everything at once, immediately.... Is there a way to conduct the search after n amount of letters are typed, or perhaps after the user hits enter?
This discussion has been closed.
Answers
Sounds like your webapp isn't fully processing the parameters sent from the clinet as described here:
https://datatables.net/manual/server-side
Likely you will want to use
LIMIT
andOFFSET
with your mysql queries to return only the rows for the requested page.One option is to use
searchDelay
. Another is to take over the global search input with your own event and use achange
event. Something similar to this example:http://live.datatables.net/jorexujo/1/edit
Kevin
Thank you, I will check out
searchDelay
and the other example for Question 2.Regarding Question 1... Is there a way to prevent the initial request for data on DT initialization? Like.... init the table, but don't get data until the user starts searching... (blank table on init)?
OR
Would it be better just to change the SQL to say, "if the search was null, return nothing"?
The
draw
parameter will be1
the for the first ajax request. You could key off that and simply return something like this:Haven't tried that but it seems like it would work
Kevin
Just FYI I ended up using
deferLoading: [0]
Forgot about that option
Kevin