Skip to content

Commit 3c68bf8

Browse files
committed
Fixed an multi select bug and eliminated duplicate docu items (yuidoc)
1 parent def17e3 commit 3c68bf8

File tree

8 files changed

+55
-23
lines changed

8 files changed

+55
-23
lines changed

Gruntfile.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ module.exports = function (grunt)
150150
version: '<%= pkg.version %>',
151151
url: '<%= pkg.homepage %>',
152152
options: {
153-
exclude: 'qunit-1.11.0.js',
154-
paths: '.',
153+
paths: '<%= pkg.folders.dist %>',
155154
outdir: '<%= pkg.folders.docs %>/'
156155
}
157156
}
183 Bytes
Binary file not shown.
228 Bytes
Binary file not shown.

build/jquery.bootgrid.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery Bootgrid v1.0.0-rc2 - 07/29/2014
2+
* jQuery Bootgrid v1.0.0-rc2 - 07/31/2014
33
* Copyright (c) 2014 Rafael Staib (http://www.jquery-bootgrid.com)
44
* Licensed under MIT http://www.opensource.org/licenses/MIT
55
*/
@@ -672,9 +672,9 @@
672672
tpl = this.options.templates,
673673
html = "",
674674
sorting = this.options.sorting,
675-
multiSelect = this.options.selection && this.identifier != null;
675+
selection = this.options.selection && this.identifier != null;
676676

677-
if (multiSelect)
677+
if (selection)
678678
{
679679
var selectBox = (this.options.multiSelect) ?
680680
tpl.select.resolve(getParams.call(that, { type: "checkbox", value: "all" })) : "";
@@ -697,6 +697,7 @@
697697

698698
headerRow.html(html);
699699

700+
// todo: create a own function for that piece of code
700701
if (sorting)
701702
{
702703
var sortingSelector = getCssSelector(css.sortable),
@@ -753,7 +754,13 @@
753754
});
754755
}
755756

756-
if (multiSelect)
757+
function filterRows(rows, id)
758+
{
759+
return rows.where(function (row) { return row[that.identifier] !== id; });
760+
}
761+
762+
// todo: create a own function for that piece of code
763+
if (selection && this.options.multiSelect)
757764
{
758765
var selectBoxSelector = getCssSelector(css.selectBox);
759766
headerRow.off("click" + namespace, selectBoxSelector)
@@ -762,19 +769,29 @@
762769
e.stopPropagation();
763770

764771
var rowSelectBoxes = $(that.element.find("tbody " + selectBoxSelector));
765-
that.selectedRows = [];
766772

767773
if ($(this).prop("checked"))
768774
{
769-
for (var i = 0; i < that.currentRows.length; i++)
775+
var filteredRows = $.extend([], that.currentRows),
776+
id,
777+
i;
778+
779+
for (i = 0; i < that.selectedRows.length; i++)
770780
{
771-
that.selectedRows.push(that.currentRows[i][that.identifier]);
781+
filteredRows = filterRows(filteredRows, that.selectedRows[i]);
772782
}
783+
784+
for (i = 0; i < filteredRows.length; i++)
785+
{
786+
that.selectedRows.push(filteredRows[i][that.identifier]);
787+
}
788+
773789
rowSelectBoxes.prop("checked", true);
774-
that.element.trigger("selected" + namespace, [that.currentRows]);
790+
that.element.trigger("selected" + namespace, [filteredRows]);
775791
}
776792
else
777793
{
794+
that.selectedRows = [];
778795
rowSelectBoxes.prop("checked", false);
779796
that.element.trigger("deselected" + namespace, [that.currentRows]);
780797
}
@@ -1298,7 +1315,7 @@
12981315
}
12991316
else
13001317
{
1301-
if ($.isFunction(formatter[key]))
1318+
if (formatter && formatter[key] && typeof formatter[key] === "function")
13021319
{
13031320
value = formatter[key](value);
13041321
}

build/jquery.bootgrid.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extensions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ if (!String.prototype.resolve)
7575
}
7676
else
7777
{
78-
if ($.isFunction(formatter[key]))
78+
if (formatter && formatter[key] && typeof formatter[key] === "function")
7979
{
8080
value = formatter[key](value);
8181
}

src/internal.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,9 @@ function renderTableHeader()
662662
tpl = this.options.templates,
663663
html = "",
664664
sorting = this.options.sorting,
665-
multiSelect = this.options.selection && this.identifier != null;
665+
selection = this.options.selection && this.identifier != null;
666666

667-
if (multiSelect)
667+
if (selection)
668668
{
669669
var selectBox = (this.options.multiSelect) ?
670670
tpl.select.resolve(getParams.call(that, { type: "checkbox", value: "all" })) : "";
@@ -687,6 +687,7 @@ function renderTableHeader()
687687

688688
headerRow.html(html);
689689

690+
// todo: create a own function for that piece of code
690691
if (sorting)
691692
{
692693
var sortingSelector = getCssSelector(css.sortable),
@@ -743,7 +744,13 @@ function renderTableHeader()
743744
});
744745
}
745746

746-
if (multiSelect)
747+
function filterRows(rows, id)
748+
{
749+
return rows.where(function (row) { return row[that.identifier] !== id; });
750+
}
751+
752+
// todo: create a own function for that piece of code
753+
if (selection && this.options.multiSelect)
747754
{
748755
var selectBoxSelector = getCssSelector(css.selectBox);
749756
headerRow.off("click" + namespace, selectBoxSelector)
@@ -752,19 +759,29 @@ function renderTableHeader()
752759
e.stopPropagation();
753760

754761
var rowSelectBoxes = $(that.element.find("tbody " + selectBoxSelector));
755-
that.selectedRows = [];
756762

757763
if ($(this).prop("checked"))
758764
{
759-
for (var i = 0; i < that.currentRows.length; i++)
765+
var filteredRows = $.extend([], that.currentRows),
766+
id,
767+
i;
768+
769+
for (i = 0; i < that.selectedRows.length; i++)
760770
{
761-
that.selectedRows.push(that.currentRows[i][that.identifier]);
771+
filteredRows = filterRows(filteredRows, that.selectedRows[i]);
762772
}
773+
774+
for (i = 0; i < filteredRows.length; i++)
775+
{
776+
that.selectedRows.push(filteredRows[i][that.identifier]);
777+
}
778+
763779
rowSelectBoxes.prop("checked", true);
764-
that.element.trigger("selected" + namespace, [that.currentRows]);
780+
that.element.trigger("selected" + namespace, [filteredRows]);
765781
}
766782
else
767783
{
784+
that.selectedRows = [];
768785
rowSelectBoxes.prop("checked", false);
769786
that.element.trigger("deselected" + namespace, [that.currentRows]);
770787
}

test/tests-rendering.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ module("render functions", {
1515
function renderInfosTest(expected, message, current, rowCount, total)
1616
{
1717
// given
18-
var
19-
instance = {
18+
var instance = {
2019
element: $("#table").data(namespace, {
2120
header: header,
2221
footer: footer

0 commit comments

Comments
 (0)