getItemMetaData breaks grouping functionality

404 views
Skip to first unread message

ncon

unread,
May 16, 2013, 8:57:43 AM5/16/13
to slic...@googlegroups.com
Hello all !

I've been fiddling a few days with slickgrid now, and i'm experiencing a rather strange problem...

I embedded the Grid in a widget-style user interface, which provides functions to load data into the grid like this:


dataView.beginUpdate();
dataView.getItems().length=0;
dataView.endUpdate();
       
enableLoadingIndicator(); // this just displays something like in the examples

$.ajax({
            type: "GET",
            url: "the-service",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: sv,
            success: function(msg) {
               
            dataView.beginUpdate();
            dataView.setItems(msg);
            dataView.endUpdate();

            disableLoadingIndicator();
            grid.invalidateAllRows();
            grid.render();
            group();
           
            },
            error: function(err) {
                alert("data error");
            }
        });


The group() makes a standard grouping action like in the examples.

Everything works fine, except that when i use getItemMetadata... Then everything breaks. Is there a special functionality for grouped views like getGroupItemMetadata or something like that?

Greetings

Nick

ncon

unread,
May 16, 2013, 9:19:34 AM5/16/13
to slic...@googlegroups.com
Sorry maybe this lacks a bit of information, but basically i want to conditionally format rows, no matter if they are grouped or not.

If i do this with no grouping, it works fine but if grouping is used, it will break and nothing except the alternating row backgrounds is shown. I can expand rows via the integrated API call but there isn't an ID assigned. This happens also if the getItemMetadata does nothing or returns nothing but null.

Should i open a Issue on Github?

ncon

unread,
May 16, 2013, 12:57:27 PM5/16/13
to slic...@googlegroups.com
I created a JSFiddle to make it easier to reproduce it.

http://jsfiddle.net/fFvFF/

Hope any of you guys can give me a little hint to solve this as i think it should be possible with a grid to group AND set row Styles :)

Greetings

ncon

unread,
May 16, 2013, 3:19:46 PM5/16/13
to slic...@googlegroups.com
Fixed.

When grouping is set, your own implementation of getItemMetadata must contain the overrides from slick.dataview.js

Just copy them from the file, i did it like this, works like a charm:

  dataView.getItemMetadata = function (row) {
      var item = dataView.getItem(rows[i]);

      if (item === undefined) {
        return null;
      }

      // overrides for grouping rows
      if (item.__group) {
        return groupItemMetadataProvider.getGroupRowMetadata(item);
      }

      // overrides for totals rows
      if (item.__groupTotals) {
        return groupItemMetadataProvider.getTotalsRowMetadata(item);
      }

      if (item.yourRowProperty == 'someValue')
      {
          return { cssClasses: 'yourClass1 yourClass2' }
      }

      return null;
    }

ncon

unread,
May 16, 2013, 3:21:56 PM5/16/13
to slic...@googlegroups.com
Oops, this won't work, it should read: var item = dataView.getItem(row);
Reply all
Reply to author
Forward
0 new messages