datatables how to ignoring rows

datatables how to ignoring rows

kwapsterkwapster Posts: 6Questions: 4Answers: 0

I am initialising datatables on a table and everything works fine.
I have a drop down menu on my page with an onchange function. When the event is triggered, some rows get hidden with display style = none.

Is there any way i can have datatables ignore the hidden rows completely (page length and entries etc).

eg, if datatables initializes and finds 10 rows, after the onchange event, 3 might be hidden. I would like datatables to "update" by only show me 7 entries available etc.

myDT = $('#itemTable').DataTable();

$("#tselection").on("change", function (e) {
setVisibility();
myDT.draw(); //also tried invalidate does not work


});
function setVisibility() {
    
    var table, tr, i;
    table = document.getElementById("itemTable");
    tr = table.getElementsByClassName("itemRow");
    
    for (i = 0; i < tr.length; i++) {

           if (tr.classList.contains(showME) {
                tr[i].style.display = "";
           }
         
            
            else {
                tr[i].style.display = "none";
            }
        }
   }

Answers

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    Datatables doesn't know that the rows are hidden. Instead of what you have you will need to create a Search plugin. See if this thread will help.

    Kevin

  • kwapsterkwapster Posts: 6Questions: 4Answers: 0

    Thanks! i've now ran into another problem.

    The search plugin solution works fine when i have page length set to ALL with the onchange listener.

    is there any way to have datatables also run the search plugin when/before it loads? that way it can "ignore" the hidden rows in cases where page length is not set to ALL

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    The search plugin solution works fine when i have page length set to ALL with the onchange listener.

    Sorry, I don't understand the problem. The search plugin run and do the same thing whether you have the page length set to all or not.

    is there any way to have datatables also run the search plugin when/before it loads?

    Initialize the search plugin before initializing Datatables and it will filter the initial table data.

    Please provide a link to your page or a test case replicating the issues so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

Sign In or Register to comment.