My team has some peculiar requirements that I need some help jerry-rigging into my server-side search. Basically, on initial display, OR, if the the search is an empty string (on any draw), I don't want to display any results in the table...
- We don't want to hit the database (do a draw) unless there's at least 2 characters in the search input. I've achieved this.
I use
deferLoading
so that I can make sure nothing is shown at the beginning on init. However, there's a problem where the info section shows"Showing 0 to 0 of 0 entries (filtered from NaN total entries)"
. I need to get NaN to say 0.When the search input is cleared, a draw happens. All records are returned. We don't want that -- We want to show nothing. I'm trying to figure out how to achieve this on the JavaScript side. I thought about loading a blank data array
[]
, and utilizing something likeajax.reload()
,datatable.clear()
,datatable.rows().add('[]')
, anddatatables.draw()
, but I can't figure out how to use this alongside server-side search.
Here's a very small part of the complicated stored procedure behind the scenes:
@DT_Search is null
or _.FullName like '%' + @DT_Search + '%'
or _.EEID_Status like '%' + @DT_Search + '%'
or AllNames like '%' + @DT_Search + '%'
or PositionTitle like '%' + @DT_Search + '%'
or SchoolOffice like '%' + @DT_Search + '%'
or Department like '%' + @DT_Search + '%'
BEST THING I CAN THINK OF: (UPPER BLOCK DOES NOT WORK, THIS IS EXAMPLE ONLY)
The best thing I can come up with is "override" the search with a ridiculous search string, something like 'zzzzzzzzzz', but this feels really kludgy.
if ((this.value = '') || (this.value.length < 2)) {
tblResults.search('_zzzzzzzzzz_').draw();
}
else if (this.value.length > 2) {
tblResults.search(this.value.trim()).draw();
};