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

grid.saveRow(); does not call the controller to update

3 Answers 452 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Arvind
Top achievements
Rank 1
Arvind asked on 23 Aug 2016, 04:32 PM

Hi,

I have a where i need to display data and have a button in each row, on click of the button need to toggle the record with selected property as 0 or 1.

I have used a custom command as i do not need to edit the records. and have used a click on the command, below is the code in the javascript method called in the click. But this makes the row editable and then updates the record but there is no post done to the controller, i have set the Update and Create event both. Please can you help and let me know if this is the current way of doing it.

columns.Command(command =>
{
   command.Custom("Set").Click("onSetActive").HtmlAttributes(new { @className = "k-icon k-update",   @title = "Set" });
   command.Custom("Unset").Click("onUnsetActive").HtmlAttributes(new { @className = "k-icon k-cancel", @title = "Unset" });
}).Width(145);

......

.Create(update => update.Action("Update", "My"))
 .Read(read => read.Action("Read", "My"))
.Update(update => update.Action("Update", "My"))
 
function onSetActive(e)
{
        e.preventDefault();
        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
        var row = $(e.currentTarget).closest("tr");
        var grid = $("#Grid").data("kendoGrid");
        grid.editRow(row);
        dataItem.Selected = 1;
        setTimeout(function () {
            grid.saveRow();
        });
 }

3 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 25 Aug 2016, 02:09 PM
Hi,

If you want to just alter the value inside the data item you can do the following.

JavaScript:
function onSetActive(e)
{
        e.preventDefault();
        var dataItem = $("#Grid").data("kendoGrid").dataItem($(e.currentTarget).closest("tr"));
        dataItem.set('Selected', 1);
 }


Regards,
Angel Petrov
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Arvind
Top achievements
Rank 1
answered on 25 Aug 2016, 02:16 PM

Hi,

I actually do not want set in the model, i would want to update my data in database and then reload the grid with the updated data if its successful. i was trying to achieve this with .saveRow(), hence even tried updating the model and trying to call this.

Thanks.

0
Angel Petrov
Telerik team
answered on 29 Aug 2016, 07:52 AM
Hello,

If you want to update the database as well you can modify the JavaScript as follows.

function onSetActive(e) {
    e.preventDefault();
    var grid = $("#Grid").data("kendoGrid");
    var row = $(e.currentTarget).closest("tr")
    grid.editRow(row);
    var dataItem = grid.dataItem(row);
    dataItem.set('Selected', false);
    grid.saveChanges();
}
If the above does not resolve the matter please share with us the entire grid configuration so we could examine the setup.

Regards,
Angel Petrov
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Arvind
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Arvind
Top achievements
Rank 1
Share this question
or