Mottie / tablesorter

Github fork of Christian Bach's tablesorter plugin + awesomeness ~
https://mottie.github.io/tablesorter/docs/
2.61k stars 754 forks source link

Filter widget unexpected behaviour when data containing space-hyphen-space #1630

Open zonehun opened 5 years ago

zonehun commented 5 years ago

Dear All,

I looked through all the relevant questions and I saw that there were some answers about the hyphen problems.I saw the Issue 1220. I tried it but it did not work.

Example: Table row conatining two rows. First column data to be filtered:

Event related things 191214 Demisec - VW meeting - table+chairs

When I start to type 1..9..1 all of the rows disappearing.

jQuery setup for my tablesorter:

                $('#report').tablesorter({
                    sortList: [[".$temp.",".$sortorder."]], 
                    headers: {
                        6: { sorter: 'digit' },
                        7: { sorter: 'digit' }
                    },
                    textExtraction: {
                        6: function(node, table, cellIndex) { return $(node).text().replace(/\s+/g, ''); },
                        7: function(node, table, cellIndex) { return $(node).text().replace(/\s+/g, ''); }
                    },
                    widthFixed : true,
                    widgets: ['filter'],
                    ignoreCase: false,
                    widgetOptions : {
                        filter_columnFilters : true,
                        filter_columnAnyMatch: true,
                        filter_excludeFilter : {
                            0: 'range'
                        },
                        filter_filteredRow : 'filtered',
                        filter_filterLabel : 'Filter {{label}} column by...',
                        filter_hideFilters : false,
                        filter_placeholder : { search : '".__("Search", "frame")."...', select : '' },
                        // Use the $.tablesorter.storage utility to save the most recent filters (default setting is false)
                        filter_saveFilters : false,
                        filter_defaultAttrib : 'data-value',
                        filter_selectSourceSeparator : '|'

                    }                   
                }); 

When I added the following textExtraction it started to work:

0: function(node, table, cellIndex) { return $(node).text().replace(/-\s/g, '-'); },

But it is not good since the exact text search would not be working. For eg. copying the exact text to the filter input field.

Do you have any idea or suggestions to solve my problem?

Thank you.

Mottie commented 5 years ago

Hi @zonehun!

Please see issue #1220. I think I need to add this to the FAQ.

zonehun commented 5 years ago

Hi @Mottie ,

I had tried already the mentioned solution in #1220. It won't work in my case.

But I figured out the root cause of the problem. If the string[s] in the cell[s] starting with numbers the filter is not able to find them. If they starting with letters then the solution in #1220 is working.

Sample string for testing: "191214 Demisec - VW meeting - table+chairs"

Do you have any idea how to solve it?

Thank you.

Mottie commented 5 years ago

Make sure that column has the text parser set on it... it might have detected that column as numeric.

Fix it by setting a "sorter-text" class in the header.

Mottie commented 5 years ago

Also, https://github.com/Mottie/tablesorter/wiki/FAQ#dashes-in-content.

zonehun commented 5 years ago

Still there. I think my exmaple is interfering with a custom parser. I downloaded and using this. Parser: date ranges -updated 11/22/2015 (v2.24.6)....

I guess this parser causing the problem.

The strange thing is that I can not set the column data sorter/parser. I tried everythingin headers, in data attribute, in class...

zonehun commented 5 years ago

OK, I found the solution. Just for the record.

I over-defined the filter algorithm for my specific column with the following:

widgetOptions : {
    filter_functions : {
        0: function(e, n, f, i, r, c, data) {
            if ( e.toLowerCase().indexOf( f.toLowerCase() ) !== -1 ) return true;
            else return false;
        }
    }
}

Now the filter is working as expected for my sepcial strings as well. :)

Issue should be closed. Thank you.