[SearchPanes, Select]: Custom search pane for selected rows
[SearchPanes, Select]: Custom search pane for selected rows
Goal:
Create a custom search pane for filtering all (un)selected rows.
Test case:
http://live.datatables.net/rolakana/1/edit?js,console,output
Steps to reproduce:
Select the first row
Notes:
- We are using var rowIds = []
to store the ids of all selected rows (to prevent infinite loops due to search pane options being (un)selected when using cascadePanes: true
- We listen to the events select.dt
and deselect.dt
to add/remove the row id and to rebuild the search pane.
- During rebuild, the function for the search pane options is called 4 times (with correct information about the selected state)
- But after the rebuild, the function is called again two times and the selected state information is missing
So after selecting the first row, the console output is:
"SELECT EVENT: REBUILD PANE 0"
"ROW 0 IS SELECTED"
"ROW 0 IS SELECTED"
"ROW 0 IS SELECTED"
"ROW 0 IS SELECTED"
"SELECT EVENT: REBUILD DONE"
"ROW 0 IS NOT SELECTED"
"ROW 0 IS NOT SELECTED"
I think it`s a bug that the information about the row being selected is missing.
This question has accepted answers - jump to:
Answers
Awww, snap, maximum confusion. This is a duplicate of
https://datatables.net/forums/discussion/72236/infinite-draw-loop-when-having-dt-rowid-in-ajax-response#latest
Hi @allan and @colin,
I was working again on that topic and suddenly a general question came up:
Is SearchPanes capable of custom search panes
(such as https://datatables.net/extensions/searchpanes/examples/customFiltering/customPane.html)
when running in
serverSide: true
mode?Even if the
options[x].value
function works and shows the filter options withcount
andtotal
,will selecting a filter option make SearchPanes filter the rows returned by the Ajax call (
data
) ?My guess is "no", because the returned
searchPanes.options
would also have to be altered (count
andtotal
).Hi Pascal,
You are absolutely correct. A custom pane would require hooks for logic and conditions on the server-side which I'm afraid the libraries do not provide at this time.
Allan
Hi @allan,
thanks for the quick answer.
For everyone struggeling to build a filter for selected rows in
serverSide: true
mode, here is a working solution:1) Add an
<input id="selectedIds" type="hidden" value="[ids from database as JSON array]">
to your website storing the ids of the selected rows2) init DataTables with selected ids added to the data option:
3) modify your serverside script to use the request variable
selectedIds
for filtering returned rows and search panes options4) add an select/deselect event handler to add/remove ids from the hidden input:
5) add an draw event handler to prevent selected rows to be unselected after using the search panes filter:
Hope that helps!
Pascal