Jquery data tables need to show only selected rows from an integer array of IDs

124
March 05, 2022, at 11:10 PM

I have a drop down with checkboxes in it. When I select multiple items, I have a method which gets those IDs in an integer array. In my data table one of the column, lets say 'User_ID:name' has those IDs. I want to loop through the data table and show only rows of selected IDs in the integer array. If array is empty, no rows should be visible.

I wrote a method, but it's only showing me only 1 row and it keeps overwriting that row when looping through.

var Gridupdate = function () {
    int[] checked = Checkbox.getCheckedIds(); /// integer array of selectedIDs from a checkbox
    if (dtable) {
        for (i = 0; i < checked.length; i++) {
            dtable.column("User_ID:name").search(checked[i].toString()).draw();
        }
    }
}
Answer 1

You can use regex in "DataTables" to achieve this. Add this to your "DataTables' initialisation options".

"search": {
    "regex": true, // enables the table to be filtered using regular expresion
    "smart": false // disables the table's "smart search" ability. Ensures a more accurate search.
}

Example:

$('#example').DataTable( {
    "search": {
        "regex": true,
        "smart": false
    }
});

And change your method to this

var Gridupdate = function () {
    var checked = Checkbox.getCheckedIds(); /// integer array of selectedIDs from a checkbox
    if (dtable) {
        dtable.column("User_ID:name").search(checked.join('|')).draw(); // eg .search(1|2|4)
    }
};
Rent Charter Buses Company
READ ALSO
Append value to ckeditor 5 in textarea jquery in modal

Append value to ckeditor 5 in textarea jquery in modal

In a bootstrap 4 modal is located a form with a textarea using CKEditor 5This form is for updating data from a database

129
How to create a TailwindCSS grid with a dynamic amount of grid columns?

How to create a TailwindCSS grid with a dynamic amount of grid columns?

I'm using Vue3 with TailwindCSS and want to create a grid with a dynamic grid-cols-{n} classI know that TailwindCSS supports up to 12 columns by default but I can't customize the theme because the amount of columns is completely dynamic

146
Background-color and spacing between posts in posting system [duplicate]

Background-color and spacing between posts in posting system [duplicate]

Now, I have a posting systemThere's an input field and a submit button

111