Is there a way to set all check boxes (in a specific column) to true or false?
I am displaying data with two check box values, each in there own column. I want to have a "Select All" button on my form, which would tick every check box in one of the columns.
Then of course I would like to be able to get these changes from the transactions log.
Is this possible? Thanks.
Hello Shaun,
Yes, it's possible.
You should have Updating feature enabled. The igGridUpdating.setCellValue is the right API.
Here is an example which updates only the visible records in the grid:
function checkAll(check) { var updating = $("#grid1").data("igGridUpdating"), grid = $("#grid1").data("igGrid"), ds = grid.dataSource, i, record; for (i = 0; i < ds.dataView().length; i++) { record = ds.dataView()[i]; updating.setCellValue(record[grid.options.primaryKey], "MakeFlag", check); }}
If you want to update all the records in the data source you should use the $("#grid1").data("igGrid").dataSource.data() API.
Hope this helps,Martin PavlovInfragistics, Inc.
Thank you for the code. This is what I'm trying to do but its not quite working.
Looking at the documentation for setCellValue, it asks for a rowID, colKey and value. From your code I see your example as
rowID : record[grid.options.primaryKey]
colKey : "MakeFlag"
value: true/false
I changed 'colKey' to the Key of the column I want to update. However when I run the code, it does cause an update because all rows change to the edited state (italic) but none of the check boxes actually change. There are entries in the transaction log for a cell update for each row though.
record[grid.options.primaryKey] returns the rowID (data-id) as a string, I tried changing this string into an int and passing that to the method. This causes the each cell to display "[object Object]", unless I click on a row to edit it, then the original data returns, until I'm done editing and it goes back to "[object Object]". This also creates an identical transaction log as before.
I've put some sample data and my igGrid setup in this pasteBin http://pastebin.com/7HmgPVk9
And my checkAll method
function checkAll(check) { var updating = $("#itemStockLocationsMaintenanceGridTable").data("igGridUpdating"); var grid = $("#itemStockLocationsMaintenanceGridTable").data("igGrid"); var ds = grid.dataSource; var i; var record;
for (i = 0; i < ds.dataView().length; i++) {
record = ds.dataView()[i]; var itemCode = record[grid.options.primaryKey]; updating.setCellValue(itemCode, "Checked", check); } }
Thank you for your help so far.
From the pasteBin I can see that the "ItemCode" field in the data source is "number", but in the grid configuration you declared it as "string", that's why you see it as a string in the checkAll function. Changing the type of the "ItemCode" column in the grid to "number" should resolve your issues.
I'm attaching a working sample for your reference.
Best regards,Martin PavlovInfragistics, Inc.
Thank you very much for your sample code. The missing like/line of code was "grid.commit();", this caused the igGrid to update the UI and add each change as a transaction.
Thank you again for your help.
I am glad to hear that you have managed to resolve this.
Thank you for working with us.