From 229cf8635304bf499d880f3b538b69803f6bf930 Mon Sep 17 00:00:00 2001 From: Matt Groth Date: Wed, 2 Aug 2017 06:56:56 -0700 Subject: [PATCH 1/2] Add deselectAll method added new deselectAll method to better support deselecting rows across pages, especially when using ajax data source --- demo/ajax.htm | 17 ++++++-- demo/{data.json => data1.json} | 17 +++----- demo/data2.json | 26 ++++++++++++ demo/server.js | 74 ++++++++++++++++++++++++++++++++++ dist/jquery.bootgrid.css | 2 +- dist/jquery.bootgrid.fa.js | 2 +- dist/jquery.bootgrid.js | 33 ++++++++++++++- package.json | 4 +- src/public.js | 31 ++++++++++++++ 9 files changed, 188 insertions(+), 18 deletions(-) rename demo/{data.json => data1.json} (60%) create mode 100644 demo/data2.json create mode 100644 demo/server.js diff --git a/demo/ajax.htm b/demo/ajax.htm index c2ce5b0..befe92a 100644 --- a/demo/ajax.htm +++ b/demo/ajax.htm @@ -56,14 +56,15 @@
- Sub Nav + +
- + @@ -89,8 +90,10 @@ ajaxSettings: { method: "GET" }, + rowCount: 5, ajax: true, - url: 'http://127.0.0.1:8080/demo/data.json', + keepSelection: true, + url: 'http://127.0.0.1:8080/data', selection: true, multiSelect: true }).on('loaded.rs.jquery.bootgrid', function(){ @@ -101,6 +104,14 @@ } }) }); + + $("#deselect").on("click", function() { + $("#grid").bootgrid("deselect"); + }); + + $("#deselectAll").on("click", function() { + $("#grid").bootgrid("deselectAll"); + }); }); diff --git a/demo/data.json b/demo/data1.json similarity index 60% rename from demo/data.json rename to demo/data1.json index 5c20b79..e33e8aa 100644 --- a/demo/data.json +++ b/demo/data1.json @@ -4,28 +4,23 @@ "rows": [{ "id": "a0e3a286-4343-4240-8d6d-e79fa2e94b4c", "sender": "test@test.de", - "received": "2014-04-17 15:08:03Z", - "checked": true + "received": "2014-04-17 15:08:03Z" }, { "id": "dd9f2d42-9442-404c-8d2a-dd3bd2156c03", "sender": "test@test.de", - "received": "2014-04-16 15:19:31Z", - "checked": true + "received": "2014-04-16 15:19:31Z" }, { "id": "e9b8ede5-c1bf-4d90-b724-e7379b25f7b3", "sender": "test@test.de", - "received": "2014-04-16 15:17:05Z", - "checked": false + "received": "2014-04-16 15:17:05Z" }, { "id": "153d3acb-efe7-4b5f-a3a9-e8ac18bdec30", "sender": "test@test.de", - "received": "2014-04-16 15:17:05Z", - "checked": true + "received": "2014-04-16 15:17:05Z" }, { "id": "49bad60a-bbf7-42bf-b040-d901805ccbf1", "sender": "test@test.de", - "received": "2014-04-15 11:23:06Z", - "checked": false + "received": "2014-04-15 11:23:06Z" }], - "total": 5 + "total": 10 } diff --git a/demo/data2.json b/demo/data2.json new file mode 100644 index 0000000..35cfbc2 --- /dev/null +++ b/demo/data2.json @@ -0,0 +1,26 @@ +{ + "current": 2, + "rowCount": 5, + "rows": [{ + "id": "V5e3a286-4343-4240-8d6d-e79fa2e94b4c", + "sender": "test@test.de", + "received": "2014-04-17 15:08:03Z" + }, { + "id": "pp9f2d42-9442-404c-8d2a-dd3bd2156c03", + "sender": "test@test.de", + "received": "2014-04-16 15:19:31Z" + }, { + "id": "p7b8ede5-c1bf-4d90-b724-e7379b25f7b3", + "sender": "test@test.de", + "received": "2014-04-16 15:17:05Z" + }, { + "id": "553d3acb-efe7-4b5f-a3a9-e8ac18bdec30", + "sender": "test@test.de", + "received": "2014-04-16 15:17:05Z" + }, { + "id": "34bad60a-bbf7-42bf-b040-d901805ccbf1", + "sender": "test@test.de", + "received": "2014-04-15 11:23:06Z" + }], + "total": 10 +} diff --git a/demo/server.js b/demo/server.js new file mode 100644 index 0000000..4fd220e --- /dev/null +++ b/demo/server.js @@ -0,0 +1,74 @@ +'use strict'; + +const Hapi = require('hapi'); + +const server = new Hapi.Server(); +server.connection({ port: 8080, host: 'localhost' }); + +server.register(require('inert'), (err) => { + + server.route({ + method: 'GET', + path: '/demo/{file}', + handler: function (request, reply) { + reply.file('./demo/' + encodeURIComponent(request.params.file)); + } + }); + + server.route({ + method: 'GET', + path: '/data', + handler: function (request, reply) { + reply.file('./demo/data' + request.query.current + '.json'); + } + }); + + server.route({ + method: 'GET', + path: '/demo/css/{name*}', + handler: { + directory: { + path: 'demo/css', + redirectToSlash: true + } + } + }); + server.route({ + method: 'GET', + path: '/dist/{name*}', + handler: { + directory: { + path: 'dist', + redirectToSlash: true + } + } + }); + server.route({ + method: 'GET', + path: '/demo/{name*}', + handler: { + directory: { + path: 'demo/', + redirectToSlash: true + } + } + }); + server.route({ + method: 'GET', + path: '/lib/{name*}', + handler: { + directory: { + path: 'lib/', + redirectToSlash: true + } + } + }); +}); + +server.start((err) => { + + if (err) { + throw err; + } + console.log(`Server running at: ${server.info.uri}`); +}); \ No newline at end of file diff --git a/dist/jquery.bootgrid.css b/dist/jquery.bootgrid.css index 4a04a3d..3164924 100644 --- a/dist/jquery.bootgrid.css +++ b/dist/jquery.bootgrid.css @@ -1,5 +1,5 @@ /*! - * jQuery Bootgrid v1.4.2 - 02/10/2017 + * jQuery Bootgrid v1.4.2 - 08/02/2017 * Copyright (c) 2014-2017 Rafael Staib (http://www.jquery-bootgrid.com) * Licensed under MIT http://www.opensource.org/licenses/MIT */ diff --git a/dist/jquery.bootgrid.fa.js b/dist/jquery.bootgrid.fa.js index a917ccd..928c54e 100644 --- a/dist/jquery.bootgrid.fa.js +++ b/dist/jquery.bootgrid.fa.js @@ -1,5 +1,5 @@ /*! - * jQuery Bootgrid v1.4.2 - 02/10/2017 + * jQuery Bootgrid v1.4.2 - 08/02/2017 * Copyright (c) 2014-2017 Rafael Staib (http://www.jquery-bootgrid.com) * Licensed under MIT http://www.opensource.org/licenses/MIT */ diff --git a/dist/jquery.bootgrid.js b/dist/jquery.bootgrid.js index f4cb6bd..a6dcb24 100644 --- a/dist/jquery.bootgrid.js +++ b/dist/jquery.bootgrid.js @@ -1,5 +1,5 @@ /*! - * jQuery Bootgrid v1.4.2 - 02/10/2017 + * jQuery Bootgrid v1.4.2 - 08/02/2017 * Copyright (c) 2014-2017 Rafael Staib (http://www.jquery-bootgrid.com) * Licensed under MIT http://www.opensource.org/licenses/MIT */ @@ -1783,6 +1783,37 @@ Grid.prototype.deselect = function(rowIds) return this; }; +/** + * Deselects all rows. + * + * @method deselectAll + * @chainable + **/ +Grid.prototype.deselectAll = function() +{ + if (this.selection) + { + if (this.selectedRows.length > 0) + { + var deselected = []; + var selectBoxSelector = getCssSelector(this.options.css.selectBox); + + this.element.find("thead " + selectBoxSelector).prop("checked", false); + for (var i = 0; i < this.selectedRows.length; i++) + { + this.element.find("tbody > tr[data-row-id=\"" + this.selectedRows[i] + "\"]") + .removeClass(this.options.css.selected)._bgAria("selected", "false") + .find(selectBoxSelector).prop("checked", false); + } + + this.selectedRows = []; + this.element.trigger("deselected" + namespace, [deselected]); + } + } + + return this; +}; + /** * Sorts the rows by a given sort descriptor dictionary. * The sort filter will be reseted, if no argument is provided. diff --git a/package.json b/package.json index 5437f95..64f18fb 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,9 @@ "grunt-contrib-yuidoc": "^1.0.0", "grunt-exec": "^1.0.0", "grunt-nuget": "~0.1.4", - "grunt-regex-replace": "^0.3.0" + "grunt-regex-replace": "^0.3.0", + "hapi": "^16.5.0", + "inert": "^4.2.1" }, "readmeFilename": "README.md" } diff --git a/src/public.js b/src/public.js index 5dbc434..44e8763 100644 --- a/src/public.js +++ b/src/public.js @@ -800,6 +800,37 @@ Grid.prototype.deselect = function(rowIds) return this; }; +/** + * Deselects all rows. + * + * @method deselectAll + * @chainable + **/ +Grid.prototype.deselectAll = function() +{ + if (this.selection) + { + if (this.selectedRows.length > 0) + { + var deselected = []; + var selectBoxSelector = getCssSelector(this.options.css.selectBox); + + this.element.find("thead " + selectBoxSelector).prop("checked", false); + for (var i = 0; i < this.selectedRows.length; i++) + { + this.element.find("tbody > tr[data-row-id=\"" + this.selectedRows[i] + "\"]") + .removeClass(this.options.css.selected)._bgAria("selected", "false") + .find(selectBoxSelector).prop("checked", false); + } + + this.selectedRows = []; + this.element.trigger("deselected" + namespace, [deselected]); + } + } + + return this; +}; + /** * Sorts the rows by a given sort descriptor dictionary. * The sort filter will be reseted, if no argument is provided. From a5148c9e6376c04f4a95b6a150c52041731f54b0 Mon Sep 17 00:00:00 2001 From: Chris Tanner Date: Thu, 24 May 2018 15:49:21 -0700 Subject: [PATCH 2/2] Escape regex characters before parsing them --- demo/index.htm | 2 +- dist/jquery.bootgrid.css | 4 ++-- dist/jquery.bootgrid.fa.js | 4 ++-- dist/jquery.bootgrid.js | 17 +++++++++++------ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/demo/index.htm b/demo/index.htm index ed4dd00..a35686e 100644 --- a/demo/index.htm +++ b/demo/index.htm @@ -274,7 +274,7 @@ - + diff --git a/dist/jquery.bootgrid.css b/dist/jquery.bootgrid.css index 3164924..3a95473 100644 --- a/dist/jquery.bootgrid.css +++ b/dist/jquery.bootgrid.css @@ -1,6 +1,6 @@ /*! - * jQuery Bootgrid v1.4.2 - 08/02/2017 - * Copyright (c) 2014-2017 Rafael Staib (http://www.jquery-bootgrid.com) + * jQuery Bootgrid v1.4.2 - 05/24/2018 + * Copyright (c) 2014-2018 Rafael Staib (http://www.jquery-bootgrid.com) * Licensed under MIT http://www.opensource.org/licenses/MIT */ .bootgrid-header, diff --git a/dist/jquery.bootgrid.fa.js b/dist/jquery.bootgrid.fa.js index 928c54e..45e152d 100644 --- a/dist/jquery.bootgrid.fa.js +++ b/dist/jquery.bootgrid.fa.js @@ -1,6 +1,6 @@ /*! - * jQuery Bootgrid v1.4.2 - 08/02/2017 - * Copyright (c) 2014-2017 Rafael Staib (http://www.jquery-bootgrid.com) + * jQuery Bootgrid v1.4.2 - 05/24/2018 + * Copyright (c) 2014-2018 Rafael Staib (http://www.jquery-bootgrid.com) * Licensed under MIT http://www.opensource.org/licenses/MIT */ ;(function ($, window, undefined) diff --git a/dist/jquery.bootgrid.js b/dist/jquery.bootgrid.js index a6dcb24..0b815c5 100644 --- a/dist/jquery.bootgrid.js +++ b/dist/jquery.bootgrid.js @@ -1,6 +1,6 @@ /*! - * jQuery Bootgrid v1.4.2 - 08/02/2017 - * Copyright (c) 2014-2017 Rafael Staib (http://www.jquery-bootgrid.com) + * jQuery Bootgrid v1.4.2 - 05/24/2018 + * Copyright (c) 2014-2018 Rafael Staib (http://www.jquery-bootgrid.com) * Licensed under MIT http://www.opensource.org/licenses/MIT */ ;(function ($, window, undefined) @@ -87,11 +87,15 @@ function highlightAppendedRows(rows) { } } +function escapeRegExp(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); +} + // Replaces all occurrences of the word in the given html // Original source: http://stackoverflow.com/questions/8503121/replace-words-in-a-string-but-ignore-html function highlightResults(html) { var that = this, - word = that.searchPhrase, + word = escapeRegExp(that.searchPhrase), tpl = this.options.templates, css = this.options.css, container = document.createElement("div"), @@ -189,6 +193,8 @@ response = { } */ + + function loadData() { var that = this; @@ -196,9 +202,8 @@ function loadData() { showLoading.call(this); function containsPhrase(row) { - var column, - searchPattern = new RegExp(that.searchPhrase, (that.options.caseSensitive) ? "g" : "gi"); - + var column; + var searchPattern = new RegExp(escapeRegExp(that.searchPhrase), (that.options.caseSensitive) ? "g" : "gi"); for (var i = 0; i < that.columns.length; i++) { column = that.columns[i]; if (column.searchable && (column.visible || that.options.searchSettings.includeHidden) &&
IDID Sender Received
20 01nulla.magna.malesuada@musProin.edu[nulla.magna.malesuada@musProin.edu 30.01.17 Ac Urna Corp. 2