Skip to content

Commit 40186cb

Browse files
committed
Added new events and minor fixes/improvements
1 parent e13b1db commit 40186cb

File tree

9 files changed

+96
-17
lines changed

9 files changed

+96
-17
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 1.4.0
4+
5+
### Enhancements & Features
6+
- Added 3 new events
7+
- **search** Fired when a search is executed
8+
- **changePage** Fired when pagination is clicked
9+
- **toggleColumn** Fired when the checkbox is clicked to show/hide a column
10+
- **changeRowCount** Fired when changing the row count
11+
- Added function that resolves the relative page the table show display after changing row count.
12+
- Added option to disable the feature to resolve relative page after changing row count. `resolvePageFromRowCount: {boolean} [true]`
13+
314
## 1.3.2
415

516
### Enhancements & Features

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"accessibility",
1414
"bootstrap"
1515
],
16-
"version": "1.3.2",
16+
"version": "1.4.0",
1717
"authors": [{
1818
"name": "Rafael Staib",
1919
"email": "me@rafaelstaib.com",

demo/index.htm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
</tr>
250250
<tr>
251251
<td>18</td>
252-
<td>Riley Vance</td>
252+
<td>2</td>
253253
<td>porttitor.interdum@pharetra.edu</td>
254254
<td>19.06.16</td>
255255
<td>Elit Nulla Facilisi Inc.</td>
@@ -258,7 +258,7 @@
258258
</tr>
259259
<tr>
260260
<td>19</td>
261-
<td>Neve Owen</td>
261+
<td>11</td>
262262
<td>nunc.sed.pede@lectusrutrum.edu</td>
263263
<td>15.11.15</td>
264264
<td>Leo Morbi Incorporated</td>
@@ -267,7 +267,7 @@
267267
</tr>
268268
<tr>
269269
<td>20</td>
270-
<td>Fredericka Turner</td>
270+
<td>01</td>
271271
<td>nulla.magna.malesuada@musProin.edu</td>
272272
<td>30.01.17</td>
273273
<td>Ac Urna Corp.</td>
@@ -479,7 +479,7 @@
479479
}
480480
},
481481
caseSensitive: false,
482-
rowCount: [-1, 10, 50, 75]
482+
rowCount: [-1, 5, 10, 15]
483483
});
484484
}
485485

dist/jquery.bootgrid.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery Bootgrid v1.3.1 - 08/04/2016
2+
* jQuery Bootgrid v1.3.2 - 08/09/2016
33
* Copyright (c) 2014-2016 Rafael Staib (http://www.jquery-bootgrid.com)
44
* Licensed under MIT http://www.opensource.org/licenses/MIT
55
*/

dist/jquery.bootgrid.fa.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery Bootgrid v1.3.1 - 08/04/2016
2+
* jQuery Bootgrid v1.3.2 - 08/09/2016
33
* Copyright (c) 2014-2016 Rafael Staib (http://www.jquery-bootgrid.com)
44
* Licensed under MIT http://www.opensource.org/licenses/MIT
55
*/

dist/jquery.bootgrid.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery Bootgrid v1.3.1 - 08/04/2016
2+
* jQuery Bootgrid v1.3.2 - 08/09/2016
33
* Copyright (c) 2014-2016 Rafael Staib (http://www.jquery-bootgrid.com)
44
* Licensed under MIT http://www.opensource.org/licenses/MIT
55
*/
@@ -362,6 +362,7 @@ function renderColumnSelection(actions) {
362362
checkbox = $this.find(checkboxSelector);
363363
if (!checkbox.prop("disabled")) {
364364
column.visible = checkbox.prop("checked");
365+
that.element.trigger('toggleColumn', [column.id, column.text, column.visible]);
365366
var enable = that.columns.where(isVisible).length > 1;
366367
$this.parents(itemsSelector).find(selector + ":has(" + checkboxSelector + ":checked)")
367368
._bgEnableAria(enable).find(checkboxSelector)._bgEnableField(enable);
@@ -478,6 +479,7 @@ function renderPaginationItem(list, page, text, markerCss) {
478479
};
479480
var command = $this.data("page");
480481
that.current = commandList[command] || command;
482+
that.element.trigger('changePage', [command.toString(), that.current]);
481483
loadData.call(that);
482484
}
483485
$this.trigger("blur");
@@ -518,15 +520,22 @@ function renderRowCountSelection(actions) {
518520
var $this = $(this),
519521
newRowCount = $this.data("action");
520522
if (newRowCount !== that.rowCount) {
521-
// todo: sophisticated solution needed for calculating which page is selected
522-
that.current = 1; // that.rowCount === -1 ---> All
523+
if(that.options.resolvePageFromRowCount){
524+
var page = that.current > 1 ? that.current : 1;
525+
var skip = that.current > 1 ? that.rowCount * (that.current-1) + 1 : 0;
526+
var newPage = skip > 1 ? Math.ceil(skip/newRowCount) : 1;
527+
that.current = newRowCount > 0 ? newPage : 1;
528+
}else{
529+
that.current = 1;
530+
}
523531
that.rowCount = newRowCount;
524532
$this.parents(menuItemsSelector).children().each(function() {
525533
var $item = $(this),
526534
currentRowCount = $item.find(menuItemSelector).data("action");
527535
$item._bgSelectAria(currentRowCount === newRowCount);
528536
});
529537
$this.parents(menuSelector).find(menuTextSelector).text(getText(newRowCount));
538+
that.element.trigger('changeRowCount' + namespace, [newRowCount]);
530539
loadData.call(that);
531540
}
532541
});
@@ -692,6 +701,7 @@ function executeSearch(phrase) {
692701
if (this.searchPhrase !== phrase) {
693702
this.current = 1;
694703
this.searchPhrase = phrase;
704+
this.element.trigger("search" + namespace, [this.searchPhrase]);
695705
loadData.call(this);
696706
}
697707
}
@@ -935,6 +945,17 @@ Grid.defaults = {
935945
columnSelection: true,
936946
rowCount: [10, 25, 50, -1], // rows per page int or array of int (-1 represents "All")
937947

948+
/**
949+
* Resolves the correct page number after changing the row count so that the top most row will remain in the table
950+
*
951+
* @property resolvePageFromRowCount
952+
* @type Boolean
953+
* @default true
954+
* @for defaults
955+
* @since 1.4.0
956+
**/
957+
resolvePageFromRowCount: true,
958+
938959
/**
939960
* Enables row selection (to enable multi selection see also `multiSelect`). Default value is `false`.
940961
*
@@ -1609,12 +1630,25 @@ Grid.prototype.sort = function(dictionary)
16091630
* Therefore be sure that only one grid instance is catched by your selector.
16101631
*
16111632
* @method getColumnSettings
1633+
* @param {Object} filter object to filter return array with
16121634
* @return {Array} Returns a list of the column settings.
16131635
* @since 1.2.0
1636+
* @version 1.4.0
16141637
**/
1615-
Grid.prototype.getColumnSettings = function()
1638+
Grid.prototype.getColumnSettings = function(filter)
16161639
{
1617-
return $.merge([], this.columns);
1640+
var res = this.columns;
1641+
if(filter && typeof filter === 'object'){
1642+
res = this.columns.filter(function(el){
1643+
for (var key in filter) {
1644+
if(el[key] !== filter[key]){
1645+
return false;
1646+
}
1647+
}
1648+
return true;
1649+
});
1650+
}
1651+
return $.merge([], res);
16181652
};
16191653

16201654
/**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "jquery-bootgrid",
33
"namespace": "jquery.bootgrid",
44
"title": "jQuery Bootgrid",
5-
"version": "1.3.2",
5+
"version": "1.4.0",
66
"description": "Nice, sleek and intuitive. A grid control especially designed for bootstrap.",
77
"homepage": "http://www.jquery-bootgrid.com",
88
"author": {

src/internal.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ function renderColumnSelection(actions) {
352352
checkbox = $this.find(checkboxSelector);
353353
if (!checkbox.prop("disabled")) {
354354
column.visible = checkbox.prop("checked");
355+
that.element.trigger('toggleColumn', [column.id, column.text, column.visible]);
355356
var enable = that.columns.where(isVisible).length > 1;
356357
$this.parents(itemsSelector).find(selector + ":has(" + checkboxSelector + ":checked)")
357358
._bgEnableAria(enable).find(checkboxSelector)._bgEnableField(enable);
@@ -468,6 +469,7 @@ function renderPaginationItem(list, page, text, markerCss) {
468469
};
469470
var command = $this.data("page");
470471
that.current = commandList[command] || command;
472+
that.element.trigger('changePage', [command.toString(), that.current]);
471473
loadData.call(that);
472474
}
473475
$this.trigger("blur");
@@ -508,15 +510,22 @@ function renderRowCountSelection(actions) {
508510
var $this = $(this),
509511
newRowCount = $this.data("action");
510512
if (newRowCount !== that.rowCount) {
511-
// todo: sophisticated solution needed for calculating which page is selected
512-
that.current = 1; // that.rowCount === -1 ---> All
513+
if(that.options.resolvePageFromRowCount){
514+
var page = that.current > 1 ? that.current : 1;
515+
var skip = that.current > 1 ? that.rowCount * (that.current-1) + 1 : 0;
516+
var newPage = skip > 1 ? Math.ceil(skip/newRowCount) : 1;
517+
that.current = newRowCount > 0 ? newPage : 1;
518+
}else{
519+
that.current = 1;
520+
}
513521
that.rowCount = newRowCount;
514522
$this.parents(menuItemsSelector).children().each(function() {
515523
var $item = $(this),
516524
currentRowCount = $item.find(menuItemSelector).data("action");
517525
$item._bgSelectAria(currentRowCount === newRowCount);
518526
});
519527
$this.parents(menuSelector).find(menuTextSelector).text(getText(newRowCount));
528+
that.element.trigger('changeRowCount' + namespace, [newRowCount]);
520529
loadData.call(that);
521530
}
522531
});
@@ -682,6 +691,7 @@ function executeSearch(phrase) {
682691
if (this.searchPhrase !== phrase) {
683692
this.current = 1;
684693
this.searchPhrase = phrase;
694+
this.element.trigger("search" + namespace, [this.searchPhrase]);
685695
loadData.call(this);
686696
}
687697
}

src/public.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ Grid.defaults = {
6161
columnSelection: true,
6262
rowCount: [10, 25, 50, -1], // rows per page int or array of int (-1 represents "All")
6363

64+
/**
65+
* Resolves the correct page number after changing the row count so that the top most row will remain in the table
66+
*
67+
* @property resolvePageFromRowCount
68+
* @type Boolean
69+
* @default true
70+
* @for defaults
71+
* @since 1.4.0
72+
**/
73+
resolvePageFromRowCount: true,
74+
6475
/**
6576
* Enables row selection (to enable multi selection see also `multiSelect`). Default value is `false`.
6677
*
@@ -735,12 +746,25 @@ Grid.prototype.sort = function(dictionary)
735746
* Therefore be sure that only one grid instance is catched by your selector.
736747
*
737748
* @method getColumnSettings
749+
* @param {Object} filter object to filter return array with
738750
* @return {Array} Returns a list of the column settings.
739751
* @since 1.2.0
752+
* @version 1.4.0
740753
**/
741-
Grid.prototype.getColumnSettings = function()
754+
Grid.prototype.getColumnSettings = function(filter)
742755
{
743-
return $.merge([], this.columns);
756+
var res = this.columns;
757+
if(filter && typeof filter === 'object'){
758+
res = this.columns.filter(function(el){
759+
for (var key in filter) {
760+
if(el[key] !== filter[key]){
761+
return false;
762+
}
763+
}
764+
return true;
765+
});
766+
}
767+
return $.merge([], res);
744768
};
745769

746770
/**

0 commit comments

Comments
 (0)