Skip to content

Commit ebdbfb2

Browse files
committed
Merge pull request wenzhixin#555 from macias3/master
Update to methods to select rows by value and documentation
2 parents aa969da + 1a560cd commit ebdbfb2

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

docs/_i18n/en/documentation/events.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,20 @@
7777
<tr>
7878
<td>onCheckAll</td>
7979
<td>check-all.bs.table</td>
80-
<td>none</td>
81-
<td>Fires when user check all rows.</td>
80+
<td>rows</td>
81+
<td>
82+
Fires when user check all rows, the parameters contains: <br>
83+
rows: array of records corresponding to newly checked rows.
84+
</td>
8285
</tr>
8386
<tr>
8487
<td>onUncheckAll</td>
8588
<td>uncheck-all.bs.table</td>
86-
<td>none</td>
87-
<td>Fires when user uncheck all rows.</td>
89+
<td>rows</td>
90+
<td>
91+
Fires when user uncheck all rows, the parameters contains: <br>
92+
rows: array of records corresponding to previously checked rows.
93+
</td>
8894
</tr>
8995
<tr>
9096
<td>onLoadSuccess</td>

docs/_i18n/en/documentation/methods.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,28 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
121121
<td>index</td>
122122
<td>Uncheck a row, the row index start with 0.</td>
123123
</tr>
124+
<tr>
125+
<td>checkBy</td>
126+
<td>params</td>
127+
<td>
128+
Check a row by array of values, the params contains:<br>
129+
field: name of the field used to find records<br>
130+
values: array of values for rows to check<br>
131+
Example: <br>
132+
$("#table").bootstrapTable("checkBy", {field:"field_name", values:["value1","value2","value3"]})
133+
</td>
134+
</tr>
135+
<tr>
136+
<td>uncheckBy</td>
137+
<td>params</td>
138+
<td>
139+
Uncheck a row by array of values, the params contains:<br>
140+
field: name of the field used to find records<br>
141+
values: array of values for rows to uncheck<br>
142+
Example: <br>
143+
$("#table").bootstrapTable("uncheckBy", {field:"field_name", values:["value1","value2","value3"]})
144+
</td>
145+
</tr>
124146
<tr>
125147
<td>resetView</td>
126148
<td>params</td>

src/bootstrap-table.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,10 +1554,16 @@
15541554
};
15551555

15561556
BootstrapTable.prototype.checkBy_ = function (checked, obj) {
1557+
if(!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) {
1558+
return;
1559+
}
1560+
15571561
var that = this;
1558-
var is_array = $.isArray(obj.value);
15591562
$.each(this.data, function (index, row) {
1560-
if(is_array ? $.inArray(row[obj.field], obj.value) != -1 : row[obj.field] == obj.value) {
1563+
if(!row.hasOwnProperty(obj.field)) {
1564+
return false;
1565+
}
1566+
if($.inArray(row[obj.field], obj.values) != -1) {
15611567
that.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
15621568
row[that.header.stateField] = checked;
15631569
that.trigger(checked ? 'check' : 'uncheck', row);

0 commit comments

Comments
 (0)