Grid Aggregates in Batch Mode

6 posts, 0 answers
  1. Lee
    Lee avatar
    20 posts
    Member since:
    Jun 2014

    Posted 13 Feb Link to this post

    I have a grouped Grid in batch mode.  My aggregates aren't refreshing as edits are made to the aggregated data until after a .saveChanges is performed.  I want the aggregate to update as soon as the focus leaves a cell that is aggregated.

    My Columns look like this:

        columns.Bound(c => c.Period1)
           .HeaderTemplate("<a>" + @title1 + "<br>" + @title2 + "</a>")
           //.ClientGroupHeaderTemplate("#= sum #")
           .ClientGroupFooterTemplate("#= sum #")
           .ClientFooterTemplate("#= sum #")
           .Filterable(false)
           .Width(100);

    My Datasource is configured as such:

        .DataSource(dataSource => dataSource
        .Ajax()
        .AutoSync(false)
        .Aggregates(aggregates =>

        {
           if (Model.Count() > 0) { aggregates.Add(p => p.Period1).Sum(); }
           //more aggregate properties here

    })
    .Batch(true)
    .ServerOperation(false)
    .Events(events => events.Error("error_handler"))
    .Group(groups => groups.Add(p => p.ProjectType))
    .Model(model =>
    {
    model.Id(prop => prop.ID);

    //other model properties here

    })
    .Create(create => create.Action("CreateManpowerProjectEstimates", "Manpower"))
    .Read(read => read.Action("ReadManpowerProjectEstimates", "Manpower"))
    .Update(edit => edit.Action("UpdateManpowerProjectEstimates", "Manpower"))
    .Destroy(delete => delete.Action("DestroyManpowerProjectEstimates", "Manpower"))
    .PageSize(20)
    )

     

  2. Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    347 posts

    Posted 17 Feb Link to this post

    Hello Lee,

    To achieve the desired behavior, you can attach a handler to the Save() event of the Kendo UI Grid and call the refresh() method in the corresponding function:

    ...
    .Events(e => e.Save("updateValues"))
    ...
     
    <script>
    function updateValues(e){
    e.sender.refresh();
    }
    </script>

    I hope this helps.

    Regards,
    Dimiter Topalov
    Telerik
    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. Lee
    Lee avatar
    20 posts
    Member since:
    Jun 2014

    Posted 18 Feb in reply to Dimiter Topalov Link to this post

    That worked like a charm for making the aggregates recalculate but after putting in the e.sender.refresh() the grid cell looses focus.  The user would have to pick up the mouse and position it on the next cell after every edit.  This isn't feasible either.  I've been trying to figure out how to determine what cell has focus before the save event is triggered and then after calling the refresh set focus back on that cell or the next cell since most likely what triggered the save is the user tabbing to the next cell.  This is what I've tried:

    var cell = $(this).closest("td");

    var colIdx = grid.cellIndex(cell);

    As I put watch points in the client script and step through the colIdx is always returning -1 regardless of what cell had focus.

  5. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 23 Feb Link to this post

    Hello Lee,

     

    We are not sure where you are attempting to get the edited cell. If you do that in the save event handler and you are using incell editing it should be possible:

     

    save: function(e) {
     var index = e.container.index();
     console.log(index);
     this.refresh();                          
    },

     

    Example - http://dojo.telerik.com/@rusev/uwUGa

     

    Regards,
    Nikolay Rusev
    Telerik
    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
  6. Lee
    Lee avatar
    20 posts
    Member since:
    Jun 2014

    Posted 03 Mar in reply to Nikolay Rusev Link to this post

    That gives me the index of the column I'm not having any luck putting focus back onto the cell.

    function updateValues(e) {
    var grid = $("#gridResourceManagerInput").data("kendoGrid");
    var index = e.container.index();
    console.log(index);
    //alert(e.sender.text());
    e.sender.refresh();
    var cell = $("#gridResourceManagerInput td:eq(" + index + ")");
    grid.current(cell);
    grid.table.focus();
    grid.editCell(cell);
    }

  7. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 07 Mar Link to this post

    Hello Lee,

     

    Can you demonstrate this in a isolated runnable example for better understanding? Thus we'll be able to debug it locally and assist you further.

     

    Regards,
    Nikolay Rusev
    Telerik
    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