Topic: datatable search via data attributes

Pierre Grobbelaar pro asked 11 months ago


I use php to fetch mysqli data to dynamically populate the table. I want the search function to search table content through data attributes.

I cant get it to filter the data because I don't know how to activate the function. Please provide a generic example of the search function using data attributes instead of javascript.Mdb basic table example


Mejuto free answered 11 months ago


Work perfect! Thank you.

Regards


Dawid Wajszczuk staff answered 11 months ago


Hi,

You just need to write this JS code

const instance = mdb.Datatable.getInstance(document.querySelector('.datatable'));

document.querySelector('#datatable-search-input').addEventListener('input', (e) => {
  instance.search(e.target.value);
});

Here is the snippet https://mdbootstrap.com/snippets/standard/d-wajszczuk/3532745#js-tab-view.

Keep coding,
Dawid


Pierre Grobbelaar pro commented 11 months ago

Exactly what I was looking for. Thank you Dawid.


Mejuto free answered 11 months ago


On the same spot, using datatable via attributes and need to seach, how to access to the row content via javascript?.

Thank you



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • User: Pro
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 3.9.0
  • Device: PC
  • Browser: Opera
  • OS: Windows
  • Provided sample code: No
  • Provided link: No