SlickGrid - applying getItemMetadata making the row to loose its id

2,461 views
Skip to first unread message

neoswf

unread,
Jun 12, 2012, 12:07:44 PM6/12/12
to slic...@googlegroups.com
I have the following problem:

I have used the collapse example, and added getItemMetadata method.

dataView.getItemMetadata = function (row) {
        var thtId = data[row].id;
        if (data[thtId + 1] && data[thtId + 1].indent > data[thtId].indent) {
            return { 'cssClasses': 'parentClassName' }
        }
    };
This works fine until I try to collapse and expanding my rows. Than I get the following error (only on expanding):

Uncaught TypeError: Cannot read property 'id' of undefined

From my experience, this error accrue when the dataView looses the children's properties. I investigated more and saw that the code fall in the appendRowHtml function (slick.grid.js#1217).

Does anyone has expirience with collapsing feature & getItemMetadata?

Thank You!

Michael Leibman

unread,
Jun 12, 2012, 1:54:47 PM6/12/12
to slic...@googlegroups.com
Debugging usually helps ;)

Shlomi Asaf

unread,
Jun 12, 2012, 2:03:45 PM6/12/12
to slic...@googlegroups.com
Agree, but I am sitting on it since yesterday, and cannot figure it out. I was hoping maybe, by any chance, somebody came across it...

It's so weird. if i'm passing a property to the rows, using  getItemMetadata method, the dataView just losses its properties, but only on expand. I still need to investigate it.

Michael Leibman

unread,
Jun 12, 2012, 2:32:52 PM6/12/12
to slic...@googlegroups.com
If you post a repro case on jsfiddle.net, I can take a quick look.

Shlomi Asaf

unread,
Jun 12, 2012, 2:34:15 PM6/12/12
to slic...@googlegroups.com
will do that now. Thank you Michael.

Shlomi Asaf

unread,
Jun 12, 2012, 4:13:06 PM6/12/12
to slic...@googlegroups.com
Hi Micheal.
Here is a Fiddle that demonstrates the problem.


I discovered an interesting behaviour. If you collapse the first father, and than collapse the second, third and on, the first won't expand, but the rest will.

Thank you.
Shlomi.

Michael Leibman

unread,
Jun 12, 2012, 4:20:23 PM6/12/12
to slic...@googlegroups.com
The exception is occurring in "var thtId = data[row].id", where "row" is out of bounds.  You should check if "data[row]" exists before accessing the "id" property.  The grid asks for a metadata for a non-existent row, which could be interpreted as a bug, but it is still useful to be able to customize the empty last row (the one used for adding new entries), so it kinda makes sense.

Shlomi Asaf

unread,
Jun 12, 2012, 4:53:39 PM6/12/12
to slic...@googlegroups.com
Thank you Michael.
I did stumbled upon that extra loop child, but didn't went all the way that direction.
Thanks a lot for your help & time.

Shlomi.

Michael Leibman

unread,
Jun 13, 2012, 1:50:40 PM6/13/12
to slic...@googlegroups.com
Your getItemMetadata implementation is flawed.  You're looking at unfiltered data ("data") instead of the filtered rows as provided by the DataView.


On Wed, Jun 13, 2012 at 10:24 AM, Shlomi Asaf <neo...@gmail.com> wrote:
Even if I'll rewrite my json & pass a 'isParent' parameter to the dataView, the behaviour still occurs.

dataView.getItemMetadata = function (row) {
if (data[row] != undefined) {
if (data[row].isParent == true) {
return { 'cssClasses': 'parentClassName' }
}
}
};

On Wed, Jun 13, 2012 at 2:21 PM, Shlomi Asaf <neo...@gmail.com> wrote:
Michael- did you noticed the following behaviour:
On collapsing the grid, the "parents" row classname been rendered & given to wrong rows. On expanding back everything get back to normal.

Shlomi Asaf

unread,
Jun 13, 2012, 1:21:19 PM6/13/12
to slic...@googlegroups.com
Michael- did you noticed the following behaviour:
On collapsing the grid, the "parents" row classname been rendered & given to wrong rows. On expanding back everything get back to normal.

Shlomi Asaf

unread,
Jun 13, 2012, 1:24:59 PM6/13/12
to slic...@googlegroups.com
Even if I'll rewrite my json & pass a 'isParent' parameter to the dataView, the behaviour still occurs.

dataView.getItemMetadata = function (row) {
if (data[row] != undefined) {
if (data[row].isParent == true) {
return { 'cssClasses': 'parentClassName' }
}
}
};

Shlomi Asaf

unread,
Jun 13, 2012, 2:48:14 PM6/13/12
to slic...@googlegroups.com
Thank you again Michael.
I hope from now on, I will stop posting these type of questions, and make sure to understand better the code.

Shomi. 

Venkata Barani

unread,
Sep 20, 2012, 7:35:56 AM9/20/12
to slic...@googlegroups.com

dataView.getItemMetadata = function () {

for(var i=0;i<data.length;i++)
{
     var thtId = data[i].id;

        if (data[thtId + 1] && data[thtId + 1].indent > data[thtId].indent) {
            return { 'cssClasses': 'parentClassName' }
        } 
}
}; 

I too got that same error.but i tried in this aspect.please try and say wheater u get the same error.

Reply all
Reply to author
Forward
0 new messages