How can I use the "Individual column searching" function for Drupal 8? I have seen that there is a patch for Drupal 7.

Thx

https://www.datatables.net/examples/api/multi_filter.html

jQuery(document).ready(function() {
  // Setup - add a text input to each footer cell
  jQuery('#datatable tfoot th').each( function () {
    var title = jQuery(this).text();
    jQuery(this).html( '<input type="text" placeholder="Search '+title+'" />' );
  } );

  // DataTable
  var table = jQuery('#example').DataTable();

  // Apply the search
  table.columns().every( function () {
    var that = this;

    jQuery( 'input', this.footer() ).on( 'keyup change clear', function () {
      if ( that.search() !== this.value ) {
        that
          .search( this.value )
          .draw();
      }
    } );
  } );
} );

I have integrated the javascript file into the website. But then I get the following error:

jquery.min.js?v=3.2.1:2 jQuery.Deferred exception: table.columns is not a function TypeError: table.columns is not a function
    at HTMLDocument.<anonymous> (http://landwehrcie.de/themes/contrib/zurb_foundation/js/init_datatables.js?v=8.7.8:12:9)
    at j (http://landwehrcie.de/core/assets/vendor/jquery/jquery.min.js?v=3.2.1:2:29999)
    at k (http://landwehrcie.de/core/assets/vendor/jquery/jquery.min.js?v=3.2.1:2:30313) undefined

Thank you for your help

Issue fork datatables-3091230

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bavramor created an issue. See original summary.

bavramor’s picture

Issue summary: View changes
isalmanhaider’s picture

Assigned: bavramor » isalmanhaider
avpaderno’s picture

Assigned: isalmanhaider » Unassigned
Category: Feature request » Support request
Issue tags: -Individual column searching (text inputs)
dqd’s picture

Status: Active » Needs work
Issue tags: +Needs reroll

How can I use the "Individual column searching" function for Drupal 8? I have seen that there is a patch for Drupal 7.

To answer the question: We need a reroll of that patch you mentioned for D8. Link to the patch? Please reference the former issue and patch here for others to be able to chime in for a reroll.

aleix’s picture

Version: 8.x-1.x-dev » 2.0.0
Status: Needs work » Needs review
StatusFileSize
new4.94 KB

I have adapted patch from https://www.drupal.org/project/datatables/issues/980424 to 2.x code, and positioned before table as there's no footer row in views tables.

patacard’s picture

Hey Aleix,

Patch looks great - installed just fine.

On initial load of the view - without the multi-filter setting enabled get an error: (after enabling multi-filter it went away)
Notice: Undefined index: multi_filter in template_preprocess_views_view_datatables() (line 47 of modules/contrib/datatables/datatables.module).

Anyway to make each column have a toggle for having a filter? Right now it's all or nothing. Would be nice to select which columns should have filters.

Thanks for the patch!

patacard’s picture

StatusFileSize
new6.71 KB

I put together the following patch that introduces the option to toggle specific column filtering and moved the filters into a tfoot area.

patacard’s picture

StatusFileSize
new11.02 KB

I went ahead and made some updates. Updated the column filter fields to select lists using DataTables APIs (source: https://www.datatables.net/examples/api/multi_filter_select.html)

I also went ahead and added a text field under the DataTables settings that allows for additional custom configurations.

dqd’s picture

Version: 2.0.0 » 2.x-dev
Status: Needs review » Needs work
Issue tags: -Needs reroll +undefined
+++ b/templates/views-view-datatables.html.twig
@@ -26,10 +26,104 @@
-{% include 'views-view-table.html.twig' %}
\ No newline at end of file

Just some nitpicking: please no NL on EOL and there are some unwanted empty lines regarding Drupal coding standarts occuring later on below that line.

Apart from that, awesome work is going on here! +1!

Please let's keep it clean and lert's patch against latest dev. I will merge the latest fixes than for the next 2.1 release.

dqd’s picture

Issue tags: -undefined
dtarc’s picture

I was able to get the patch in #8 running but could not get the patch in #10 to work. It applied to the latest dev but the select filters just wouldn't seem to display.

anybody’s picture

Having the same requirement, I'll pick this up and finalize it.

I had a look at patches #8 and #10 and dislike the complexity of #10. As DataTables is a JavaScript solution, and we want to add some JS sugar functionality here, we should not overwrite the whole template file for this.

I may change my mind later on, but I don't think it's worth it, if it can be solved in JavaScript like the whole library, see https://datatables.net/examples/api/multi_filter_select.html

So I'll base my implementation on #8, not on #10 and will create an issue fork for that.

anybody’s picture

Here's the interdiff from #8 and #10 FYI, I'll try to take the best from both worlds in the MR.

anybody’s picture

Title: Individual column searching » Individual column searching & filtering (select / input in the table header / footer)
anybody’s picture

Category: Support request » Feature request
Status: Needs work » Active
anybody’s picture

I decided to implement the settings like hidden_columns to stick to existing form structure & implementation.

anybody’s picture

IMPORTANT:

Note that if you wish to use the search abilities of DataTables this must remain true - to remove the default search input box whilst retaining searching abilities (for example you might use the search() method), use the dom option.

(Source: https://datatables.net/reference/option/searching)
So I made the options dependent and added a highlighted information on that. The search input can be hidden by sDOM value.

anybody’s picture

Status: Active » Needs review

Works quite nice, ready for review :) Please have a try!

Would be cool to get this into 2.0.1!

thomas.frobieter’s picture

Status: Needs review » Reviewed & tested by the community

The responsive style inside the TH is still problematic, our goal was to have the label aligned top and the filter field aligned bottom.
Sadly we are not able to set the new .filter-column__title-filter-wrapper to 100% height of the TH and use Flexbox to align the contents.

So it seems, the only unhacky solution here is vertical-align:bottom on the TH, so label + filter field are aligned bottom.

However, the rest looks fine to me - if the CSS styles not part of this issue: +1 RTBC.

dqd’s picture

Awesome progress here and thanks @ all working on this! Sorry for being late to chime in as co-maintainer. Will review asap now and commit.

anybody’s picture

Suuuuuper cool @diqidoq! We're successfully using this on several projects FYI. :)

  • diqidoq committed b4285a79 on 2.x authored by Anybody
    Issue #3091230 by Anybody, patacard, aleix: Individual column searching...
dqd’s picture

Status: Reviewed & tested by the community » Fixed

Sorry for being late ... again... finally merged/pushed! And upcoming release will have this awesome work done here being added. Thanks @ all and a belated HAPPY NEW YEAR.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.