Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed invalid regular expression error on search box. #268

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -7,4 +7,5 @@ src/*.map
*.diff
*.patch
.DS_Store
settings.json
settings.json
bower_components/
1 change: 1 addition & 0 deletions demo/index.htm
Original file line number Diff line number Diff line change
@@ -189,6 +189,7 @@
return "<a href=\"#\">" + column.id + ": " + row.id + "</a>";
}
},
caseSensitive: false,
rowCount: [-1, 10, 50, 75]
});
}
Binary file removed dist/jQuery.Bootgrid.1.3.1.nupkg
Binary file not shown.
Binary file modified dist/jquery.bootgrid-1.3.1.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions dist/jquery.bootgrid.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* jQuery Bootgrid v1.3.1 - 09/11/2015
* Copyright (c) 2014-2015 Rafael Staib (http://www.jquery-bootgrid.com)
* jQuery Bootgrid v1.3.1 - 02/17/2016
* Copyright (c) 2014-2016 Rafael Staib (http://www.jquery-bootgrid.com)
* Licensed under MIT http://www.opensource.org/licenses/MIT
*/
.bootgrid-header,
18 changes: 9 additions & 9 deletions dist/jquery.bootgrid.fa.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*!
* jQuery Bootgrid v1.3.1 - 09/11/2015
* Copyright (c) 2014-2015 Rafael Staib (http://www.jquery-bootgrid.com)
* jQuery Bootgrid v1.3.1 - 02/17/2016
* Copyright (c) 2014-2016 Rafael Staib (http://www.jquery-bootgrid.com)
* Licensed under MIT http://www.opensource.org/licenses/MIT
*/
;(function ($, window, undefined)
{
/*jshint validthis: true */
"use strict";

$.extend($.fn.bootgrid.Constructor.defaults.css, {
icon: "icon fa",
iconColumns: "fa-th-list",
iconDown: "fa-sort-desc",
iconRefresh: "fa-refresh",
iconSearch: "fa-search",
iconUp: "fa-sort-asc"
$.extend($.fn.bootgrid.Constructor.defaults.css, {
icon: "icon fa",
iconColumns: "fa-th-list",
iconDown: "fa-sort-desc",
iconRefresh: "fa-refresh",
iconSearch: "fa-search",
iconUp: "fa-sort-asc"
});
})(jQuery, window);
4 changes: 2 additions & 2 deletions dist/jquery.bootgrid.fa.min.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* jQuery Bootgrid v1.3.1 - 09/11/2015
* Copyright (c) 2014-2015 Rafael Staib (http://www.jquery-bootgrid.com)
* jQuery Bootgrid v1.3.1 - 02/17/2016
* Copyright (c) 2014-2016 Rafael Staib (http://www.jquery-bootgrid.com)
* Licensed under MIT http://www.opensource.org/licenses/MIT
*/
!function(a,b,c){"use strict";a.extend(a.fn.bootgrid.Constructor.defaults.css,{icon:"icon fa",iconColumns:"fa-th-list",iconDown:"fa-sort-desc",iconRefresh:"fa-refresh",iconSearch:"fa-search",iconUp:"fa-sort-asc"})}(jQuery,window);
3,302 changes: 1,666 additions & 1,636 deletions dist/jquery.bootgrid.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/jquery.bootgrid.min.css
6 changes: 3 additions & 3 deletions dist/jquery.bootgrid.min.js

Large diffs are not rendered by default.

29 changes: 25 additions & 4 deletions src/internal.js
Original file line number Diff line number Diff line change
@@ -159,16 +159,37 @@ function loadData()
this.element._bgBusyAria(true).trigger("load" + namespace);
showLoading.call(this);

function stringSearch(needle, haystack)
{
var index;
if (that.options.regexSearch) {
index = haystack.search(needle);
} else {
index = haystack.toLowerCase().indexOf(needle);
}
return index > -1 ? true : false;
}

function getRegexSearchPhrase (searchPhrase) {
return new RegExp(searchPhrase, that.options.caseSensitive ? "g" : "gi");
}

function getPlainSearchPhrase (searchPhrase) {
return that.options.caseSensitive ? searchPhrase : searchPhrase.toLowerCase();
}

function containsPhrase(row)
{
var column,
searchPattern = new RegExp(that.searchPhrase, (that.options.caseSensitive) ? "g" : "gi");
var column;
var searchPattern =
that.options.regexSearch ?
getRegexSearchPhrase(that.searchPhrase) :
getPlainSearchPhrase(that.searchPhrase);

for (var i = 0; i < that.columns.length; i++)
{
column = that.columns[i];
if (column.searchable && column.visible &&
column.converter.to(row[column.id]).search(searchPattern) > -1)
if (column.searchable && column.visible && stringSearch(searchPattern, column.converter.to(row[column.id])))
{
return true;
}
9 changes: 9 additions & 0 deletions src/public.js
Original file line number Diff line number Diff line change
@@ -208,6 +208,15 @@ Grid.defaults = {
**/
caseSensitive: true,

/**
* Defines if regex should be used when searching
*
* @property regexSearch
* @type Boolean
* @for defaults
**/
regexSearch: true,

// note: The following properties should not be used via data-api attributes

/**