How to Keep DataTables SearchBuilder Always Open

How to Keep DataTables SearchBuilder Always Open

Fotis18Fotis18 Posts: 2Questions: 1Answers: 0

Hi everyone,

I am working on a Drupal 10 website where I have integrated the DataTables library along with the SearchBuilder plugin. My goal is to achieve the following functionality:

  • Keep the SearchBuilder UI always open by default, even if no filters are applied.

Ensure the SearchBuilder UI remains open even after applying or modifying filter criteria.

Any guidance or suggestions would be greatly appreciated. Thank you in advance for your help!

// Initialize DataTables
$('.view-id-index_of_archive_files table.views-table').DataTable({
  dom: 'QBfrtip', // Adds SearchBuilder to the DataTable UI
  responsive: true,
  paging: true,
  searching: true,
  searchBuilder: true, // Enable SearchBuilder
  ordering: true,
  searchBuilder: {
    alwaysOpen: true,
    columns: [0, 1, 2], // Apply SearchBuilder only to specific columns (0 = first column, etc.)
 
},

initComplete: function (settings, json) {
  // Ensure SearchBuilder is displayed after DataTable initialization
  const searchBuilderElement = $('.dtsb-searchBuilder');
  if (!searchBuilderElement.hasClass('dtsb-active')) {
    searchBuilderElement.addClass('dtsb-active').show(); // Force it to remain open
  }

      // Automatically add a condition by simulating a click on "Add Condition"
      const addConditionButton = $('.dtsb-add');
      if (addConditionButton.length > 0) {
        addConditionButton.trigger('click');
      }
},
});



});

Answers

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    If we take this example, do you mean don't show a "Add Condition" button? Just immediately show a condition?

    Allan

  • Fotis18Fotis18 Posts: 2Questions: 1Answers: 0

    Hello allan,

    With the SearchBuilder plugin, and by default, the SearchBuilder UI only displays a button labeled "Add Condition." The user needs to click this button to open the SearchBuilder interface.

    I want to know if there is a built-in DataTables option or configuration to make the SearchBuilder UI always open on page load, as if the "Add Condition"

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    There is currently no such option. Your workaround to triggering the button on init is a good workaround until such an option is added. A pull request adding it (with docs and unit tests) would be very welcome.

    Allan

Sign In or Register to comment.