davidb
davidb

Reputation: 273

Calculated Column in Jqgrid

I have the following Grid -

https://jsfiddle.net/ht94wbtr/1/,

please see image below

enter image description here

in this Grid, i want to have a calculated column 'Total Red Cells' like below sample image

enter image description here

with the help of Oleg sir, i got this below code which can be used for Footer

        var errorInfo = {id: "Errors:", color_name: 0, character_name: 0};
    var i, item;
    for (i = 0; i < mydata.length; i++) {
        item = mydata[i];

        if ($.inArray(item.color_name, hilightcolorcell) < 0) {
            errorInfo.color_name++;
        }
        if ($.inArray(item.character_name, hilightcahractercell) < 0) {
            errorInfo.character_name++;
        }
    }

        footerrow: true,
        userDataOnFooter: true,
        userData: errorInfo //{ id: "Errors:", color_name: 2, character_name: 2 }

i would like to know how to loop through color_name and character_name columns and display the total error count in a calculated column 'Total Red Cells' as shown in the sample image. please help.

Upvotes: 0

Views: 703

Answers (1)

Oleg
Oleg

Reputation: 221997

If I correctly understand what you need then the solution would be very easy. First of all you need define the column where you will be hold/display the "Total red cells" information. Let us the column have the name redtotal. Then you should extend errorInfo to hold redtotal property with the corresponding value. The corresponding code could be like errorInfo

var errorInfo = {id: "Errors:", redtotal: 0, color_name: 0, character_name: 0};
var i, item;
for (i = 0; i < mydata.length; i++) {
    item = mydata[i];

    if ($.inArray(item.color_name, hilightcolorcell) < 0) {
        errorInfo.color_name++;
        errorInfo.redtotal++;
    }
    if ($.inArray(item.character_name, hilightcahractercell) < 0) {
        errorInfo.character_name++;
        errorInfo.redtotal++;
    }
}

You will see the results on https://jsfiddle.net/OlegKi/ht94wbtr/4/

Upvotes: 2

Related Questions