Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we change width of search fields in DataTables

Can I change the width of search text fields in dataTables ?

I am writing following code right now but it is not working.

$('#example').dataTable()
          .columnFilter({   sPlaceHolder: "head:before",
                    aoColumns: [    { type: "text",width:"10px" },
                                { type: "date-range" },
                                                { type: "date-range" }
                        ]

        });

And if my dataTables is dynamically generated like as gven below:

$('#example').dataTable({
                                "aaData": aDataSet,
                                "aoColumns": [
                                    { "sTitle": "#","sWidth": "10px" },
                                    { "sTitle": "ID" },
                                    { "sTitle": "Staff Name" },
                                    { "sTitle": "Rig Days" },
                                    { "sTitle": "Manager"},
                                    { "sTitle": "Grade"},
                                    { "sTitle": "Tools"},
                                    { "sTitle": "Vacations"},
                                    { "sTitle": "Presently On"},
                                    ]
                            });
                            }

How to add Search field in this dynamically created DataTable to search by each column?

like image 297
user2767347 Avatar asked Sep 15 '13 18:09

user2767347


People also ask

How do I create a DataTable width?

As such, if you apply the width attribute to the HTML table tag or inline width style ( style="width:100%" ), it will be used as the width for the table (overruling any CSS styles).

What is autoWidth in DataTable?

The autoWidth option is used to specify whether the automatic calculation of the column width in the DataTable is enabled or not. This calculation takes a little time and may be disabled when the column widths are explicitly passed using the columns.

What is FixedColumns in DataTables?

FixedColumns provides the option to freeze one or more columns to the left or right of a horizontally scrolling DataTable. This allows information in the fixed columns to remain visible even when scrolling through the data set. This can be particularly useful if you wish to show a large number of columns.

What is stateSave in DataTables?

DataTables saves the state of a table (its paging position, ordering state etc). When the stateSave option is enabled, it can be restored when the user reloads a page, or comes back to the page after visiting a sub-page.


2 Answers

To change the search box width, all I had to do was go into my .css file and enter the following:

.dataTables_filter input { width: 300px }
like image 119
Flea Avatar answered Sep 21 '22 03:09

Flea


it's worked for me

    <script>
    var datatable = $('#table').DataTable({
    ...<datatables properties>,
    initComplete: function () {
    $('.dataTables_filter input[type="search"]').css({ 'width': '350px', 'display': 'inline-block' });
    }
</script>
like image 22
mehmetgelmedi Avatar answered Sep 20 '22 03:09

mehmetgelmedi