Search
Search
Well, I'm back!
After a boot drive failure, I sent my SSD to a firm in Los Angeles. They were able to recover over 99% of the data--my web development (under Apache24) and my PostreSQL (under Program Files). I thought that I never would see my stuff again. And now I store my PostgreSQL database elsewhere!
Anyway... When I click in the Search box at the top left of a page, what event is triggered? I find that--if I have first selected a row on my datatable--the
table.on('select.dt', function(e, dt, type, indexes) {
is still triggered after I type the first letter/character in the Search box.
How can I stop this?
This question has accepted answers - jump to:
Answers
The
search
anddraw
events will fire.If you are using server side processing then the selected rows will be reselected after the page update, for example:
https://live.datatables.net/qoliyehi/126/edit
Select a Name beginning with
A
then typea
and after the server side processing ajax response is received you will see theconsole.log
output in theselect
event.Kevin
Kevin,
Thanks for the example. That exactly how mine behaves.
What is the best way around that? (How can or deselect the row first? Or how can I recognize that it's "selected" after entering the first character?)
Is there something in your
select
event that causes issues when searching? What are you doing in the event handler?Here are some options I can think of:
search.return
so the Datatables search is performed only on hitting enter.event preXhr
to deselect all the rows usingrows().deselect()
.select
event executes. Set the flag variable globally totrue
. Set the flag totrue
at the end of theselect
event. Set the flag tofalse
inpreXhr
. Inselect
place all the code inside an if statement and only execute it if the flag istrue
.There are probably other ways to handle this. It just depends on the problem you are having and what behavior you really want.
Kevin
Kevin,
That is exactly the issue!
I "borrowed" from your parent-child detail examples. Rather than only expanding the child details when the row header is clicked, I can also show "hierarchy" data when the row is selected. But I want/need to check first if there is hierarchy data. However, on the second hit (when the first character is typed in the Search), "ih2" in line 15 is undefined. I do not understand why; since the row is still selected, why isn't "dt" defined?
dt
is a variable representing the Datatables API.. Sodt.data()
will return all data not just row or rows selected. You will probably want to get the selected row, like line 4, except use the singlerow
, for example:I'm not sure what
ih2
is and if it contains the objectparent
. That part is dependent on your data structure.Kevin
Hi Kevin,
Thank you!
Incidentally, the variable
ih2
in question comes from the Editor PHP equivalent of the following SQL (I have to see it in SQL to write PHP), and it does contain the fieldparent
:Basically, only an item that has subordinate items will have a "1" for parent; all others will have a "0".