How to filter DATATABLES WITH TABLEDIT ?

How to filter DATATABLES WITH TABLEDIT ?

gaetanrootgaetanroot Posts: 5Questions: 0Answers: 0
edited October 2019 in Free community support

Hello everyone,
I need your help. I must used DATABLES WITH TABLEDIT.
In my category column, I need to have a select option with all categories.
When I need to search on my table, all rows are displayed because we have the match in the select option.
I need to filter results only on <span class="tabledit-span"> tag.
I don't know how to use regex with it.
Thanks in advance for your help.

My actual script:

var select = $('<select><option value=""></option></select>')
                var val = $.fn.dataTable.util.escapeRegex(
 
                            $(this).val()
 
                        );
                
                if ( table.column(i).search() !== this.value ) {
                    var val = this.value;
                    var regex = `/<span class=\"tabledit-span\">.*" + val + ".*<.*span>/`;
table
        .column(i).search( val ? regex : '', true, false );

I tried with this line but

var val = "keywords";
var regex = "/<span class=\"tabledit-span\">.*" + val + ".*<.*span>/";

table.column(i).search( val ? regex : '', true, false )

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Replies

  • gaetanrootgaetanroot Posts: 5Questions: 0Answers: 0

    Here my HTML source code:

    <span class="tabledit-span">ASS</span><select class="tabledit-input form-control input-sm" name="coloris" style="display: none;" disabled=""><option value="0">---</option><option value="BE">BE</option><option value="BC">BC</option><option value="BL">BL</option><option value="CR">CR</option><option value="CC">CC</option><option value="DR">DR</option></select>

    I need to search only on <span class="tabledit-span">ASS</span> element.

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Hi @gaetanroot ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • gaetanrootgaetanroot Posts: 5Questions: 0Answers: 0

    Hello,
    For example, when I want filter on Office column. I don't want to take the search on select element too.

    Name Position Office Age Start date Salary
    Name Position Office Age Start date Salary
    Tiger Nixon System Architect EdinburghEdinburghEdinburghSan FranciscoNew YorkNew YorkLondon 61 2011/04/25 $3,120
    Garrett Winters Director EdinburghEdinburghEdinburghSan FranciscoNew YorkNew YorkLondon 63 2011/07/25 $5,300
    Ashton Cox Technical Author San FranciscoEdinburghEdinburghSan FranciscoNew YorkNew YorkLondon 66 2009/01/12 $4,800
    Cedric Kelly Javascript Developer EdinburghEdinburghEdinburghSan FranciscoNew YorkNew YorkLondon 22 2012/03/29 $3,600
    Jenna Elliott Financial Controller EdinburghEdinburghEdinburghSan FranciscoNew YorkNew YorkLondon 33 2008/11/28 $5,300
    Brielle Williamson Integration Specialist New YorkEdinburghEdinburghSan FranciscoNew YorkNew YorkLondon 61 2012/12/02 $4,525
    Herrod Chandler Sales Assistant San FranciscoEdinburghEdinburghSan FranciscoNew YorkNew YorkLondon 59 2012/08/06 $4,080
    Rhona Davidson Integration Specialist EdinburghEdinburghEdinburghSan FranciscoNew YorkNew YorkLondon 55 2010/10/14 $6,730

    Thanks in advance.

    Gaëtan

  • gaetanrootgaetanroot Posts: 5Questions: 0Answers: 0

    Each office name are in option fields
    For the first line
    Edinburgh

    SELECT
    option
    Edinburgh
    option
    San Francisco
    option
    New York
    option
    London
    END OF SELECT

  • gaetanrootgaetanroot Posts: 5Questions: 0Answers: 0
  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Hi @gaetanroot ,

    That fiddle doesn't run. Tabledit isn't one of ours, it's a third-party library, so it would be worth addressing this with the Tabledit author or posting on Stackoverflow.

    Cheers,

    Colin

This discussion has been closed.