How to Recalculate datasource aggregates as soon as a grid field updated

5 posts, 0 answers
  1. Cagatay
    Cagatay avatar
    15 posts
    Member since:
    Dec 2011

    Posted 28 Dec 2011 Link to this post

    I've following datasource and grid configuritaion :

    dsDetail = new kendo.data.DataSource({
        schema: {
            type: "json",
            model: {
                id: "id",
                fields: {
                    c_pmprj: { validation: { required: true }},
                    c_pmchart: { validation: { required: true }},
                    dt: {/*type: "date",*/ validation: { required: true } },
                    slip_nro: {validation: { required: true }},
                    defi: { type: "string" },
                    amn: { type: "number", validation: { required: true, min: 1} },
                    vat01: {type: "number"},
                    vat08: {type: "number"},
                    vat18: {type: "number"},
                    c_zadcity: {type: "string"},
                    id: {type: "number"}
                }
            }
        },
        aggregate: [{ field: "amn", aggregate: "sum" }],
        change: function (e) {
            //
        }
    });    
     
    gridDetail = $("#grid_pmexpense").kendoGrid({
        dataSource: dsDetail,
        //height: 250,
        //filterable: true,
        scrollable: false,
        pageable: false,
        //selectable: 'row',
        sortable: true,
        editable: true,
        navigatable: true,
        columns : [ {field: "c_pmprj", title: "Proje", width: "120px", editor: prjEditor},
                    {field: "c_pmchart", title: "Masraf", width: "300px", editor: chartEditor},
                    {field: "dt", title: "Belge Tar.", width: "120px", editor:dateEditor /*format: "{0:dd.MM.yyyy}"*/},
                    {field: "slip_nro", title: "Belge No", width: "120px"},
                    {field: "defi", title: "Açıklama", width: "220px", editor: noteEditor},
                    {field: "amn", title: "Top.Tutar", width: "120px", template: '<span style="float:right">#= amn #</span>'},
                    {field: "vat01", title: "KDV %1", width: "100px", template: '<span style="float:right">#= vat01 #</span>'},
                    {field: "vat08", title: "KDV %8", width: "100px", template: '<span style="float:right">#= vat08 #</span>'},
                    {field: "vat18", title: "KDV %18", width: "100px", template: '<span style="float:right">#= vat18 #</span>'},
                    {
                        field: "id",
                        title: "İşlemler",
                        template: detailGridActionTemplate,
                        width:  "130px"}                       
                    ],
     
        change : function(e) {
            //
        },
        save: function (e) {
                $("#amn_tot").data("kendoNumericTextBox").value(this.dataSource.aggregates().amn.sum);
        },
        saveChanges: function(e) {
            //alert('save');
        }
    });    

    But this code does not update $("#amn_tot") field with new summed value... In fact this.dataSource.aggregates().amn.sum call always return initial summed up value... How do I recalculate aggregate value? Am I missing something ?

    Thanks.

  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    1876 posts
    Member since:
    Sep 2012

    Posted 29 Dec 2011 Link to this post

    Hello Cagatay,

    The aggregates will be refreshed every time fresh data is retrieved from the DataSource. Thus aggregates will be refreshed in change event of the DataSource instead of save event of the Grid.

    All the best,
    Nikolay Rusev
    the Telerik team

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!

  3. Cagatay
    Cagatay avatar
    15 posts
    Member since:
    Dec 2011

    Posted 30 Dec 2011 Link to this post

    Hi Nikolay,

    So this means when user is editing a grid aggregates will not reflect current grand total until a new post or get request?

    By the way I've tried dataset's change method and as you've mentioned it does not trigger when user edits a data...

    IMHO this feature should be implemented, in a business application users generally need to see updated grand totals as soon as they edit a row... 

    Regards...

  4. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    1876 posts
    Member since:
    Sep 2012

    Posted 03 Jan 2012 Link to this post

    Hello Cagatay,

    Please check the following jsFiddle to see how this can be achieved by editing Amount column.

    Regards,
    Nikolay Rusev
    the Telerik team

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!

  5. Cagatay
    Cagatay avatar
    15 posts
    Member since:
    Dec 2011

    Posted 26 Feb 2012 Link to this post

    Awesome, thanks..

Back to Top