Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additonal grid key information #227

Closed
jimmccarthy opened this issue Apr 28, 2016 · 5 comments
Closed

Additonal grid key information #227

jimmccarthy opened this issue Apr 28, 2016 · 5 comments

Comments

@jimmccarthy
Copy link

This is minor enhancement, but something I needed when trying to deal with handling group calculations. For some of the summary callback methods, there is a group object that contains the following attributes:

{ idx: i, 
  dataIndex: fieldName, 
  value: v, 
  displayValue: displayValue, 
  startRow: irow, 
  cnt: 1, 
  summary: [] }

So when I access this group object I can see the display value, the value, the idx (level) etc. The problem is if I have multiple nested group levels, I can not access the parent information for a given group, onlly the group key values for the current group. By adding the following code in groupingPrepare to track keys:

                // JMM - Track full key structure for groups
                var keys = [];
                for (i = 0; i < groupLength; i++) {
                    fieldName = grp.groupField[i];
                    displayName = grp.displayField[i];
                    v = record[fieldName];

                    keys.push(v);

                    displayValue = displayName == null ? null : record[displayName];

...

                        newGroup = { idx: i, 
                            dataIndex: fieldName, 
                            value: v, 
                            displayValue: displayValue, 
                            startRow: irow, 
                            cnt: 1, 
                            keys: keys,
                            summary: [] };

I now have the full key values for a given group object.

Thanks,

Jim

@OlegKi
Copy link
Member

OlegKi commented Apr 28, 2016

Thank you for your suggestion! I think it's the good idea. I would just like to discuss with you in which form it would be better to provide the information in newGroup to simplify custom processing of summary in the common case. I want to stress that the required information is already available, but the data are not so easy to use. I describe below how one could get the required information using the current version of jqGrid.

I created the demo, which demonstrates it. I used requireJs in the demo. You can see the main JavaScript here the JavaScript code. The demo displays
grouping1
where I marked the standard summary in total column with green color. I suppressed displaying total summary on the top level in the column.

The summary in note column is the mostly interesting for you. I marked the top summary with yellow color. It's calculated by

function (value, name, record, newGroup) {
    return value ? value + ", " + record[name] : record[name];
}

I marked the second level summary with orange color. It's calculated by

function (value, name, record, newGroup) {
    if (value) {
        // Continue the calculation. We append the record value
        return value + ", \"" + record[name] + "\"";
    } else {
        // start of calculation of the summary for the group
        var groupFields = this.p.groupingView.groupField, keys = [], i;
        for (i = 0; i <= newGroup.idx; i++) {
            keys.push("\"" + record[groupFields[i]] + "\"");
        }
        return keys.join("->") + ": \"" + record[name] + "\"";
    }
}

You can see that the summary function have full access to the stack of the grouping keys and to all items from the current group.

I included inline editing buttons additionally, which shows that the grouping summary values will be not automatically recalculated on editing the items. The summary values will be refreshed only after reloading of the page.

If I correctly understand your question then the demo demonstrates what you asked for.

Best regards
Oleg

P.S. Some times before you wrote that your company plant to contribute the development of free jqGrid by donating via PayPal. It's not required of cause, but it would be helpful for me. You can find more details in the README.

@OlegKi
Copy link
Member

OlegKi commented Apr 29, 2016

@jimmccarthy Do you tried the above suggestions? Could you implement your requirement now?

@jimmccarthy
Copy link
Author

Hi Oleg,

For my current issue I just needed the group field keys, but I could see
how having access to all group levels in summary for each field could also
be useful down the road.

Whatever is easier I guess.

Sorry about the donation, I made the request to my manager a while back. I
will follow up on it.

Thanks,

Jim

On Friday, April 29, 2016, Oleg Kiriljuk notifications@github.com wrote:

@jimmccarthy https://github.com/jimmccarthy Do you tried the above
suggestions? Could you implement your requirement now?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#227 (comment)

@OlegKi
Copy link
Member

OlegKi commented Apr 30, 2016

The value of the group field keys are inside of record. The current group field key is record[this.p.groupingView.groupField[newGroup.idx]]. All array with keys can be filled with

var groupFields = this.p.groupingView.groupField, keys = [], i;
for (i = 0; i <= newGroup.idx; i++) {
    keys.push(record[groupFields[i]]);
}

I think I will extend the newGroup with keys property filled before calling of the summary callback.

OlegKi added a commit that referenced this issue Apr 30, 2016
The property `keys` is added to `newGroup` parameter of the callback function `summaryType` of grouping. See [the issue](#227) for more details.
@OlegKi
Copy link
Member

OlegKi commented Apr 30, 2016

I committed the changes to GitHub. Now newGroup contains the keys property. I'm closing the issue. You can reopen it at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants