How to create a badge element for each selected value of the Searchpanes
How to create a badge element for each selected value of the Searchpanes

How can I create a badge element for each selected value? The badge should have the label and a clickable 'x'. When the 'x' is clicked, it triggers the deselect method on that pane's selection and redraws the table.
I tried to use an AI; here's the code: https://live.datatables.net/soniruzo/4/edit
But it doesn‘t work.
Please help me check where the error is.
I attached an example from another website of how it should work.
Replies
Some changes in style
https://live.datatables.net/soniruzo/5/edit
That AI generated code won't work. At this time there are no documented/public events for SearchPanes. So the event handler
dt.on('searchpanes.updated', function() { ... })
never fires.This was a fun exercise to create this morning:
https://live.datatables.net/hihukoru/1/edit
It uses the
select
anddeselect
events of the Datatables that SearchPanes creates. For example:Using
/searchPanes.container()
you can limit the tables found to just the SearchPanes container.The event handler use the
indexes
parameter to fetch therows().data()
of the selected rows. Usepluck()
to get thedisplay
object (the text displayed in the SearchPane. UsetoArray()
to convert the result to a JS array.The example uses the function
updateBadges()
to manages the "badges". To keep things simple the example doesn't actually use badges. I will let you build the code for this. Instead it just displays the selected results in adiv
.For the function refer to the following Datatables API's:
table().node()
row()
with therow-selector
as a function.row().deselect()
Hope this gets you started.
Kevin