Skip to content

Instantly share code, notes, and snippets.

@alexanderankin
Last active June 3, 2017 20:05
Show Gist options
  • Save alexanderankin/7da0a1c193e2a7317611becf9ed853d7 to your computer and use it in GitHub Desktop.
Save alexanderankin/7da0a1c193e2a7317611becf9ed853d7 to your computer and use it in GitHub Desktop.
Feature Submission

Feature Request: NULL filtering

Motivation

To be able to configure an option to be able to filter rows without content inside of them. This is useful in tandem with the other search features present in this software when dealing with incomplete data.

Changes Summary

In the function which filters an individual column, I have implemented logic which runs a truth test on the cell value instead of checking against regex. With additional knowledge as to the inner workings of this library, this value could be configurable via an API, perhaps at initialization.

{
"name": "datatables.net",
"description": "DataTables for jQuery ",
"main": [
"js/jquery.dataTables.js"
],
"keywords": [
"filter",
"sort",
"DataTables",
"jQuery",
"table",
"DataTables"
],
"dependencies": {
"jquery": ">=1.7"
},
"moduleType": [
"globals",
"amd",
"node"
],
"ignore": [
"composer.json",
"datatables.json",
"package.json"
],
"authors": [
{
"name": "SpryMedia Ltd",
"homepage": "https://datatables.net"
}
],
"homepage": "https://datatables.net",
"license": "MIT"
}
/* This starts on line 4353 in the copy of the software I have received. */
/**
* Filter the table on a per-column basis
* @param {object} oSettings dataTables settings object
* @param {string} sInput string to filter on
* @param {int} iColumn column to filter
* @param {bool} bRegex treat search string as a regular expression or not
* @param {bool} bSmart use smart filtering or not
* @param {bool} bCaseInsensitive Do case insenstive matching or not
* @memberof DataTable#oApi
*/
function _fnFilterColumn ( settings, searchStr, colIdx, regex, smart, caseInsensitive )
{
if ( searchStr === '' ) {
return;
}
var data;
var out = [];
var display = settings.aiDisplay;
var rpSearch = _fnFilterCreateSearch( searchStr, regex, smart, caseInsensitive );
for ( var i=0 ; i<display.length ; i++ ) {
data = settings.aoData[ display[i] ]._aFilterData[ colIdx ];
// if ( rpSearch.test( data ) ) {
if ( ( searchStr === '*' && data ) || rpSearch.test( data ) ) {
out.push( display[i] );
}
}
settings.aiDisplay = out;
}
{
"name": "Experiment-Viewer",
"description": "",
"main": "",
"authors": [
"Dave Ankin <alexanderankin@gmail.com>"
],
"license": "ISC",
"homepage": "",
"private": true,
"dependencies": {
"datatables.net": "^1.10.15",
"datatables.net-bs": "^2.1.1",
"bootstrap": "3.3.6",
"datatables.net-dt": "^3.2.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment