Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: datatable search via data attributes

Pierre Grobbelaar priority asked 3 years 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 3 years ago


Work perfect! Thank you.

Regards


Dawid Wajszczuk staff answered 3 years 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 priority commented 3 years ago

Exactly what I was looking for. Thank you Dawid.


Mejuto free answered 3 years 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

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