Restrict the first column filter to the first four chars

Restrict the first column filter to the first four chars

m75sam75sa Posts: 132Questions: 30Answers: 0
edited April 2022 in Free community support

Hi,
considering this example:
https://datatables.net/examples/api/multi_filter_select.html

I don't know how to restrict the filter string length of the first column only to the first 4 chars...
I saw that the select options menu item is the same for all the column... so i'm wondering if i change the first one the will change also the others... :(

Any help on this?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,345Questions: 26Answers: 4,954
    Answer ✓

    On line 5 the API for the particular column is gotten, ie, var column = this;. You can use column().index() to get the column index. Maybe add var colIndex = column.index(); below var column = this;``.

    If the index is 0, the first column, you will need to use a different regex expression in this statement:

                            column
                                .search( val ? '^'+val+'$' : '', true, false )
    

    The regex expression you use will be specific to your requirements but it might be as simple as removing the `+'$'.

    Next you might want to change the select options value to only be 4 characters if the column index is 0, ie, this code:

                    column.data().unique().sort().each( function ( d, j ) {
                        select.append( '<option value="'+d+'">'+d+'</option>' )
                    } );
    

    Kevin

Sign In or Register to comment.