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

4 posts, 0 answers
  1. Arvind
    Arvind avatar
    7 posts
    Member since:
    Aug 2016

    Posted 23 Aug Link to this post

    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();
            });
     }

  2. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 25 Aug Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Arvind
    Arvind avatar
    7 posts
    Member since:
    Aug 2016

    Posted 25 Aug Link to this post

    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.

  5. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 29 Aug Link to this post

    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready