I have small table built using jqxGrid. The 1st column contains checkboxes like below:
Expected result:
- On click of Uncheck All, need all these check-boxes to be un-checked like this:
- On click of remove need to get data of checkbox selected rows.
HTML:
JavaScript
x
4
1
<div id='travelGrid'></div>
2
<br>
3
<button id="unselect">Unselect All</button>
4
Remove
JS:
JavaScript
1
56
56
1
$( document ).ready(function() {
2
var travelGridSource = {
3
localdata: [],
4
datafields: [
5
{ name: 'isSelected', type: 'bool' },
6
{ name: 'Zipcode', type: 'number' },
7
{ name: 'TravelFee', type: 'number' }
8
],
9
datatype: "array"
10
}
11
12
13
var travelFees = [
14
{ "isSelected": "true", "Zipcode": "001", "TravelFee": "25"},
15
{ "isSelected": "true", "Zipcode": "002", "TravelFee": "75"},
16
{ "isSelected": "false", "Zipcode": "003", "TravelFee": "75"},
17
{ "isSelected": "true", "Zipcode": "004", "TravelFee": "75" },
18
{ "isSelected": "false", "Zipcode": "004", "TravelFee": "75" }
19
];
20
21
travelGridSource.localdata = travelFees;
22
23
$("#travelGrid").jqxGrid({
24
width: '100%',
25
height: '20%',
26
rowsheight: 29,
27
columnsheight: 29,
28
source: new $.jqx.dataAdapter(travelGridSource),
29
sortable: true,
30
columnsresize: true,
31
columnsmenu: false,
32
showsortcolumnbackground: false,
33
enablehover: false,
34
selectionmode: 'none',
35
scrollmode: 'logical',
36
theme: 'light',
37
rowdetails: true,
38
editable: true,
39
showrowdetailscolumn: false,
40
columns: [
41
{ text: '', datafield: 'isSelected', width: '7%', align: 'center', columntype: 'checkbox', cellsalign: 'center', 'editable': true },
42
{ text: 'Zip', datafield: 'Zipcode', width: '15%', align: 'center', cellsalign: 'center', 'editable': false },
43
{ text: 'Travel Fee', datafield: 'TravelFee', width: '20%', align: 'center', cellsalign: 'center', cellsformat: 'c2'}
44
]
45
});
46
});
47
48
49
$('#unselect').click(function(){
50
// Do something here
51
});
52
53
$('#remove').click(function(){
54
// Do something here
55
});
56
Have surfed lot and the documentation too but no use. Couldn’t able to append fiddle link, So pasted the fiddle URL as code:
JavaScript
1
2
1
https://jsfiddle.net/75zrfko0/25/
2
Advertisement
Answer
First you have to take your unselect click event in scope of of jQuery document due to you local scope of dataset.
JavaScript
1
4
1
$(document).ready(function(){
2
//unselect onclick event listener
3
})
4
Then on click of that button you have to update that local dataset from which you are adding flags for checkboxes & lastly have to update source in jqxGrid that you have taken.
JavaScript
1
10
10
1
$('#unselect').click(function(){
2
// Do something here
3
travelFees = travelFees.map((obj) => {
4
obj.isSelected = "false";
5
return {obj};
6
})
7
travelGridSource.localdata = travelFees;
8
$("#travelGrid").jqxGrid({source: new $.jqx.dataAdapter(travelGridSource)});
9
});
10
I haven’t fully gone through API for JQXWiget but there can be a method to update local dataset please follow the below link,