Skip to content

release of colsearch plugin for DataTables#145

Open
zepernick wants to merge 4 commits intoDataTables:masterfrom
zepernick:master
Open

release of colsearch plugin for DataTables#145
zepernick wants to merge 4 commits intoDataTables:masterfrom
zepernick:master

Conversation

@zepernick
Copy link
Copy Markdown

This is a plugin I wrote that will add inputs / selects to the grids header or footer for searching. It will automatically fire the search for the columns on the keyup for inputs and change for selects.

There is a delay on the keyup on the input that utilizes the searchDelay option on the DataTable. The default is 500ms if it has not been specified. The search fields are automatically omitted for a column if columns.searchable is FALSE.

Here are the plugin options:

  • placement - String: "head' or "foot" (default "head")
  • select - Array of objects: define which columns should search via dropdown. Object properties specified below.
    • name - int or string: column index, columns.data as a string, columns.name
    • options - Array of Strings or a function function(select): The function will be responsible for appending the <option/> elements to the select passed in. The select it a jQuery object. The string array can specify the value and text of the option by using a | in the String "avalue|Text To DIsplay". The plugin will assign the String to the value and text of the option if the pipe is omitted.
    • header - boolean: True to generate an option header in the select. (default true)
    • placeholders - boolean: True generates a placeholder attribute on the inputs using the column header in the table.
    • controlClass - String: Classes to apply to the controls. (default "form-control" for Bootstrap)

Plugin can be invoked by doing:

var dt = $("#mytable").DataTable();
//using defaults
new $.fn.dataTable.DtServerColSearch(dt);
//OR 
new $.fn.dataTable.DtServerColSearch(dt, {
    placement: "foot",
    placeholders: "false",
    ....
});

@DataTables
Copy link
Copy Markdown
Collaborator

This looks great - thanks for the PR! I haven't tried it out yet, and will do so before I pull it in, but just to check, are you happy for it to be released under the MIT license (like the rest of the software in this repo)? Also, could you add a copyright notice to the code for yourself / company / whatever, just to note it as your own work! :-)

@zepernick
Copy link
Copy Markdown
Author

Thanks! I am good with the MIT license. I added it to the top of the code and marked me as the author :-)

…ot carry the right number of cells.

Bug Fix: Added a listener for columns being hidden so that the plugin could adjust the search bar at the time of hiding.
@zepernick
Copy link
Copy Markdown
Author

this is now broken with the release of responsive 2.0. I am working on an update, but it is also going to require a small update to responsive to add a new event. Just a heads up for anyone who might be trying to use this! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants