This is a migrated thread and some comments may be shown as answers.

Multi Row Edit?

6 Answers 421 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 20 Sep 2012, 10:48 AM
Is it possible in the grid to select multiple rows and edit them as 1? So can I select 20 rows and with one click set some value to true?

6 Answers, 1 is accepted

Sort by
0
Nohinn
Top achievements
Rank 1
answered on 20 Sep 2012, 11:45 AM
You could change them via javascript if you only want to set a property with an unique value.
Though you will have to do some work on it:
  1.  first if you're using batch editing mode you will have to place a selector column (with chechbox), if you're not using the batch editing mode then you have the multiple select option.
  2. you will have to loop the selected items, get their dataItem, change the value and send the new updated dataItem to the grid:
    for (var i = 0; i < selected.length; i++) {
        var dt = g.dataItem(selected[i]);
        dt.property = true;
        g._modelChange({field: "property", model: dt});
    }
    Where selected will be an array containing the selected tr dom elements, and g will be the grid data: $('#grid').data('kendoGrid')
0
Michael
Top achievements
Rank 1
answered on 20 Sep 2012, 04:08 PM
Nohinn. So I'm trying what you've suggested. Im trying to set a textual value in the cell. Im using something like dt.property = "hello". When I rung this cells in the grid indcate that they have been changed but the value remains the same. And when I click the save changes nothing gets submited.
0
Michael
Top achievements
Rank 1
answered on 20 Sep 2012, 04:37 PM
Apologies. I had a mistake in the code and can now change the value in the cells which is great. But when I click on the 'save' in the toolbar it doesn't submit the changes.
0
Accepted
Nohinn
Top achievements
Rank 1
answered on 20 Sep 2012, 04:46 PM
You could try and force those items to be dirty so they look like to be updated:
http://jsbin.com/afuzoh/1/edit

Let me know if this fixes your issue.
0
Michael
Top achievements
Rank 1
answered on 20 Sep 2012, 05:25 PM
Thanks Nohinn! That works.

Question, as I was searching around I saw some references to some code like

var model = dataSource.get(id);
model.set("foo", "bar"); // changes model foo field's value to bar

Is this also another possible way to set a cell value? I couldn't get it to work though.

Outside the grid I tried something like:
var grid = $("#grid").data("kendoGrid");
var
model = grid.dataSource.get(id);
model.set("foo", "bar"); // changes model foo field's value to bar
0
Nohinn
Top achievements
Rank 1
answered on 21 Sep 2012, 08:04 AM
Yes, you can do it this way too:
var grid = $('#grid').data('kendoGrid');
var model = grid.dataSource.getByUid("UidValue");
model.set("Property", value);

With the getByUid, getting it from the tr data-uid attribute, and then setting the correct format value (string, number, ...)

P.S: Here you have the previous sample updated using this way http://jsbin.com/afuzoh/2/edit 
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Nohinn
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Share this question
or