1

Hello stackoverflow users,

I have a table that is already grouped by a column, format of this column is something like: 01100000-8

What I want to do is group if first 5 digits are equal and not all string, for example:

01100000-8 - GROUPED 1

01100303-4 - GROUPED 1

01100003-9 - GROUPED 1

11203453-2 - GROUPED 2

11203657-1 - GROUPED 2

Any one knows how can I achieve this?

Thanks in advance.

Regards, Marcelo

lmarcelocc
  • 1,301
  • 11
  • 21
  • I am not sure that I understand you correct. The 5 digits of the first 3 items are the same, but the first 5 digits of the next two items are different (`11203` and `57815`), but you want to place there in the same group "GROUPED 2". Do you made typing error and the last item should be in the next group ("GROUPED 3") or you need to have another criterion for grouping of items. – Oleg May 13 '15 at 12:11
  • @Oleg, it was a typo error, sorry for that. I have corrected. Thanks. – lmarcelocc May 13 '15 at 12:41

1 Answers1

1

You are not the first person who have the problem. During answering on the question I had the idea how to modify the code of jqGrid and to introduce isInTheSameGroup callback function which can be used to specify which items should be interpreted as identical. For example the most common case will be to ignore the time and to group the column with the datetime by date only.

In case of usage such isInTheSameGroup callback it should be important to use another callback formatDisplayField which shows how to display the grouping header. It's clear that if you place 01100000-8, 01100303-4 and 01100003-9 in the same group then displaying of 01100000-8 as the grouping header would be not good. So one should use the callback formatDisplayField to cut the displayed filed till the same first 5 digits which you use for grouping: 01100.

I didn't tested, but I think that you should use something like the following

groupingView: {
    ...
    formatDisplayField: [
        function (displayValue) { //, value, cm, index, grp) {
            return String(displayValue).substring(0, 5);
        }
    ],
    isInTheSameGroup: function (x, y) {
        return String(x).substring(0, 5) === String(y).substring(0, 5);
    }
}
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Awesome! Thanks for your help and for your contribution to jqgrid :) – lmarcelocc May 13 '15 at 16:26
  • 1
    @lmarcelocc: You are welcome! By the way, if you not yet know, I continue development of free version of jqGrid as a fork based on jqGrid 4.7 (the last free version). You can download it [here](https://github.com/free-jqgrid/jqGrid). See [wiki](https://github.com/free-jqgrid/jqGrid/wiki) and [readme](https://github.com/free-jqgrid/jqGrid/blob/master/README.md) for more detailsabout new features which I implemented. I plan to release free jqGrid 4.9 very soon. – Oleg May 13 '15 at 16:34
  • Hello @Oleg, do you know how can I display on `formatDisplayField: [ function (displayValue) { // Display next hidden field on grouped { } ]` the next existing hidden field in that grouped? Thank you in advance. – lmarcelocc May 14 '15 at 10:46
  • @lmarcelocc: Sorry, but I don't understand what you mean. The callback functions from `formatDisplayField` array have in general 5 parameters. Moreovere you should understand that the callback is to display **grouping header for the group which consist from multiple rows**. So I don't understand which hidden field from which row (rows) you need to display. Probably it's better if you would post new question with *an example* with test data and the description of results which you want to display. – Oleg May 14 '15 at 10:58
  • Thanks @Oleg, will set another question and try to explain better :) – lmarcelocc May 14 '15 at 11:00
  • Hi @Oleg, I have posted here http://stackoverflow.com/questions/30236480/jqgrid-using-formatdisplayfield-option Hope you can give me a hand I hope I have neen clear enough :) – lmarcelocc May 14 '15 at 11:42