Search code examples
jqgrid

Count number of rows based on filter JQGrid


JQ grid having column name mobile

I have jq grid which has column 'Mobile Login',It contains values 'Yes' and 'No' only. My requirement is to get count of 'Yes' value and show in footer. Currently i am using below code in load complete event of JQ Grid

grid.jqGrid("getCol", colName, false, "count")

Is their any way to add condition where value = 'Yes' in jqgrid.


Solution

  • There are many ways to do this, but it is needed to have more information on your jqGrid configuration - like datatype, loadonce and etc.

    To solve the problemin based on your information, you can just use the getCol, but to return array from object values and then looping this array can give you the needed result.

    var colvals = grid.jqGrid("getCol", colName, true),
    len = colvals.length,
    i=0,
    yescounter=0;
    
    while(i<len) {
        if(colvals[i].value === 'Yes') {
            yescounter++;
        }
        i++;
    }
    

    Hope this helps