2

I have setup drag and drop headings to group by the relevant column from jQgrid Grouping Drag and Drop

It works great however I am trying to display the column name before the value i.e.

Client : Test data data
Client : Test2 data data

I've been going around in circles if any one could help.
if i take the same code used for the dynamic group by which should be the (column Name)
I end up with The Column data not the column name.

$('#' + gridId).jqGrid('groupingGroupBy', getheader());

function getheader() {
    var header = $('#groups ol li:not(.placeholder)').map(function () {
                      return $(this).attr('data-column');
                 }).get();
    return header;
}

if i use the same function in group text I get data not the column name.

I've come from C# and I am very new to jQuery.

If any one could help it would be greatly appreciated.

Kind Regards,
Ryan

Oleg
  • 220,925
  • 34
  • 403
  • 798
rize17
  • 25
  • 4

1 Answers1

1

First of all the updated demo provides the solution of your problem:

enter image description here

Another demo contains simplified demo which demonstrates just how one could display the grouping header in the form Column Header: Column data in the grouping header instead of Column data used as default.

The main idea of the solution is the usage of formatDisplayField property of groupingView which I suggested originally in the answer. The current version of jqGrid support the option. If one would use for example the options

grouping: true,
groupingView: {
    groupField: ["name", "invdate"],
    groupColumnShow: [false, false],
    formatDisplayField: [
        customFormatDisplayField,
        customFormatDisplayField
    ]
}

where customFormatDisplayField callback function are defined as

var customFormatDisplayField = function (displayValue, value, colModel) {
    return colModel.name + ": " + displayValue;
}

will display almost the results which you need, but it will uses name property of colModel instead of the corresponding name from colNames. To makes the final solution one use another implementation of customFormatDisplayField:

var getColumnHeaderByName = function (colName) {
        var $self = $(this),
            colNames = $self.jqGrid("getGridParam", "colNames"),
            colModel = $self.jqGrid("getGridParam", "colModel"),
            cColumns = colModel.length,
            iCol;
        for (iCol = 0; iCol < cColumns; iCol++) {
            if (colModel[iCol].name === colName) {
                return colNames[iCol];
            }
        }
    },
    customFormatDisplayField = function (displayValue, value, colModel, index, grp) {
        return getColumnHeaderByName.call(this, colModel.name) + ": " + displayValue;
    };
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Also remove a heading doesn't seem to work it also makes place holder disappear if you remove all the groups. Any ideas? – rize17 Jul 29 '14 at 15:05
  • @rize17: It was a small bug in the other part of the demo. [The demo](http://jsfiddle.net/vRtKS/96/) fixes the problem. – Oleg Jul 29 '14 at 16:11
  • I have one last problem. I have a DateTime as a grouped column. In the previous source (My Post) it worked fine. The new source I'm having trouble with. The formater for the column is "width: 100, sorttype: 'date', formatter: 'date', formatoptions: { newformat: 'd/m/y H:i' }". The date is displayed as "03/07/14 09:22" in the column (as usual) but the header is "Date: /Date(1404372141000)/" I could use "if (colModel.name == "Date") {'convert displayValue'}" in customFormatDisplayField but I don't know what how I convert 1404372141000 into 03/07/14 09:22. Thanks again for the help. – rize17 Jul 30 '14 at 06:52
  • @rize17: You are welcome! Formatting of grouping header using the formatter of the corresponding grouping column is *new question*. Searching engine don't search in comments. – Oleg Jul 30 '14 at 08:38
  • Thanks I will post it under a new Question – rize17 Jul 30 '14 at 09:33