0

I'm with a problem using jqgrid with some options, better that write is show you an image: jQGrid

So, when I'm construction the table body (with ajax call) I'm passing an hidden field. When something is grouped, I want to show that hidden field where 'undefined' word is (group title).

Is there any solution using formatDisplayField?

What I have is something like:

groupingView : {
                    groupField : ['cpv'],
                    groupCollapse : true,
                    groupOrder: ['desc'],
                    plusicon: 'ui-icon-circle-plus',
                    minusicon: 'ui-icon-circle-minus',
                    formatDisplayField: [
                    function (value) { // Should be cpv_parent (hidden by default but sent to jggrid when instantiate)
console.log(value); // Contain CPV Grouped
console.log($(this)); // Contain [table#ajaxTable.ajaxTable.ui-jqgrid-btable, context: table#ajaxTable.ajaxTable.ui-jqgrid-btable, constructor: function, init: function, selector: "", jquery: "1.7.2"…]
                        //return String(displayValue).substring(0, 5);
                    }
                    ],
                    isInTheSameGroup: function (x, y) {
                        return String(x).substring(0, 5) === String(y).substring(0, 5);
                    }
                }

EDIT As required, heres a sample data form what i'm using (from last try (using userData)):

{"total":1,"page":1,"totalrecords":3,"userdata":{"98513295":"98000000-3"},"rows":[{"tipoConcurso":"Ajuste Directo (Regime Geral)","createdOn":"2014-04-23 16:19:56","valor":15000,"cpv":98513295,"cpvParent":"98000000-3"},{"tipoConcurso":"Ajuste Directo (Regime Geral)","createdOn":"2013-10-01 16:05:08","valor":15000,"cpv":98513295,"cpvParent":"98000000-3"},{"tipoConcurso":"Ajuste Directo (Regime Geral)","createdOn":"2013-09-03 17:34:39","valor":15000,"cpv":98513295,"cpvParent":"98000000-3"}]}

Thanks @Oleg :)

Thank you all in advance :)

Regards, Marcelo

lmarcelocc
  • 1,301
  • 11
  • 21
  • could you provide the demo with the test data (3 rows - one group) which reproduce the problem. It's unclues for me for example whether one have the same `ajaxTable_cpvParant` value in all rows on the group. I suppose that placing the information as hidden column is the wrong way and it would be better to post the information separately as `userdata` for example. It's difficult to understand the problem without the demo. – Oleg May 14 '15 at 12:11
  • Look at [the demo](http://jsfiddle.net/OlegKi/78m7jdaz/3/). Probably it do already close things to what you need. It uses one more approach in usage of `summaryType` as function in the grouping column. It uses additionally `userdata` to provides additional information like youth from `ajaxTable_cpvParant`. It loads the data via Ajax like you do. The `serverResponse` is the response from the server. – Oleg May 14 '15 at 12:30
  • The same demo, but using free jqGrid looks as http://jsfiddle.net/OlegKi/78m7jdaz/4/ – Oleg May 14 '15 at 13:24
  • Thanks @Oleg. And how to apply that to `groupingView : { groupText: // HERE }` I can't get there :( – lmarcelocc May 14 '15 at 14:10
  • `groupText` could be callback function in [free jqGrid](https://github.com/free-jqgrid/jqGrid). One can use `formatDisplayField` as function. I asked you to provide simple test data and test jqGrid with grouping. I would modify it to show how to implement the requirements. – Oleg May 14 '15 at 16:04
  • Hello @Oleg, I have provide a sample data. Thank you so much for your help :) – lmarcelocc May 14 '15 at 17:02

1 Answers1

2

It's a little difficult to understand your question because you display some abstract numbers only. I understand you so. You make grouping by cpv filed, but you need to display another field cpvParent which can be get based on the cpv value. One need just to have a map which get cpvParent from cpv. I don't recommend to add any hidden columns which are more expensive.

So I suggest that you change the data

{
    "total": 1,
    "page": 1,
    "totalrecords": 3,
    "rows": [
        {
            "tipoConcurso": "Ajuste Directo (Regime Geral)",
            "createdOn": "2014-04-23 16:19:56",
            "valor": 15000,
            "cpv": 98513295,
            "cpvParent": "98000000-3"
        },
        {
            "tipoConcurso": "Ajuste Directo (Regime Geral)",
            "createdOn": "2013-10-01 16:05:08",
            "valor": 15000,
            "cpv": 98513295,
            "cpvParent": "98000000-3"
        },
        {
            "tipoConcurso": "Ajuste Directo (Regime Geral)",
            "createdOn": "2013-09-03 17:34:39",
            "valor": 15000,
            "cpv": 98513295,
            "cpvParent": "98000000-3"
        }
    ]
}

to the following:

{
    "total": 1,
    "page": 1,
    "totalrecords": 3,
    "userdata": {
        "98513295": "98000000-3",
        "97123456": "97000000-2"
    }
    "rows": [
        {
            "tipoConcurso": "Ajuste Directo (Regime Geral)",
            "createdOn": "2014-04-23 16:19:56",
            "valor": 15000,
            "cpv": 97123456,
            "cpvParent": "98000000-3"
        },
        {
            "tipoConcurso": "Ajuste Directo (Regime Geral)",
            "createdOn": "2013-10-01 16:05:08",
            "valor": 15000,
            "cpv": 98513295
        },
        {
            "tipoConcurso": "Ajuste Directo (Regime Geral)",
            "createdOn": "2013-09-03 17:34:39",
            "valor": 15000,
            "cpv": 98513295
        }
    ]
}

Inside of formatDisplayField callback you can get userData parameter (the name of parameter is userData, but the JSON data have to have userdata in other case). Now the userData[value] will get you "98000000-3" by key "98513295":

groupingView: {
    groupField: ["cpv"],
    ...
    formatDisplayField: [
        function (value) {
            var userData = $(this).jqGrid("getGridParam", "userData");
            return userData[value];
        }
    ]
}

Such way will work quickly and you need just prepare the data on the server side in the above format.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hi @Oleg, good morning! Yo uhave understand well my example, I will try it right now. But if you see, in my last attempt, I have already the correct data retrieve form server :) Have tryied now and yes, it's working and now I understand must better how this works :) Thank you so much for your help :) – lmarcelocc May 15 '15 at 08:49