Example of SearchBuilder field property with the column definition

Example of SearchBuilder field property with the column definition

tacman1123tacman1123 Posts: 217Questions: 50Answers: 1

I'm following the example here: https://datatables.net/reference/feature/searchBuilder.columns

new DataTable('#myTable', {
    layout: {
        top1: {
            searchBuilder: {
                columns: [1, 2, 3]
            }
        }
    }
});

Because my data is dynamic, it's a challenge to keep track of the column indexes. The columns are created via the API. Is there a way to either reference the column but something besides an index, or defining the searchBuilder in the column itself?

new DataTable('#myTable', {
    layout: {
        top1: {
            searchBuilder: {
                columns: ['year','quantity_sold']
            }
        }
    }
});

This is supported in SearchPanes, so maybe it's already supported, but I can't find documentation.

 let column = { 
          data: 'year'
};

// this works for searchPanes
            column.searchPanes = {
                show: c.browsable,
                dtOpts: {
                    info: true,
                    columnDefs: [
                        {
                            targets: 0,
                            className: 'f32'
                        }
                    ]
                }
            };

// does this even exist?  What are the options?
            column.searchBuilder = {
                type: 'date'
            }

Thx.

Answers

  • kthorngrenkthorngren Posts: 21,554Questions: 26Answers: 4,994

    To use a classname for the selector you need to prefix with a period, for example:

    columns: ['.year','.quantity_sold']
    

    See the column-selector docs, specifically using a string, for more details.

    Kevin

Sign In or Register to comment.