Search code examples
jqgridmvcgrid

how footerdata set jqgrid set dynmaic column


iam create jqgrid dynmamic but i have problem. when create footer jqgrid

call function sumarValores() for footer in loadComplete but dont know global when use $self.jqGrid Must use Price_Num instead of global ;but I do not want use Price_Num direct in $self.jqGrid iam want create dynmamic footer.

dataArray = [
      { id_R: 1, Name_c: "dummy1",  AddDate_D: "1394/07/27", Price_Num: "10000" },
      { id_R: 2, Name_c: "dummy2", AddDate_D: "1394/07/28", Price_Num: "120000" },

]; this my code

 $('#list').jqGrid({
        caption: "",    
        datatype: 'local',
        colNames: getColNames(dataArray[0]),
        colModel: getColModels(dataArray[0]),
     footerrow : true,
    loadComplete: function () {
            sumarValores($(this))
          },
});
function sumarValores($self) {
    var sumaHa = 0;
    var columnNames = jQuery("#list").jqGrid('getGridParam', 'colNames');
    var global;
    for (var z = 0; z < columnNames.length; z++) {
        var colN = columnNames[z];
        if (colN == "Price")
        {
            colN = colN.concat('_Num');
            global =  colN;
            var sumCanceled = $self.jqGrid("getCol", colN, false, "sum");
            break;
        }

    }

    alert(colN);
    global ='Price_Num';
    $self.jqGrid("footerData", "set", {
        global : sumCanceled,

    });

    }

Solution

  • The problem I see here is that you can't set the object property the way you do.

    global ='Price_Num';
    $self.jqGrid("footerData", "set", {
        global : sumCanceled,
    
    }); 
    

    To overcome this you can do

    global ='Price_Num';
    var footer = {};
    footer[global] = sumCanceled;
    $self.jqGrid("footerData", "set", footer );
    

    Hope this helps