Search code examples
objectslickgriddataview

SlickGrid DataView set colspan using value from row


I am trying to implement an updating colspan on certain items in a SlickGrid:

This part of the code works fine:

dataView.getItemMetadata = function (row) {

  if (0 == 0) {
    return {
      "columns": {
        "heading": {
          "colspan": "*"
        }
      }
    };
  } else {
    return {
      "columns": {
        "heading": {
          "colspan": 1
        }
      }
    };
  }
};

It give all items a colspan as expected, but i want to get the value within the "highlight" column and use that to determine if the "heading" column gets a colspan applied. This needs to update every time the checkbox in the highlight column is clicked. So i need to get the value of the "highlight" column on that row.

If i run this:

  console.log(dataView.getItem(row));

I get multiple items like this:

Object {id: "id_5", highlight: 1, heading: "voluptatem", quoted: 0…}

But if I run this:

  console.log(dataView.getItem(row).highlight);

I get this:

Uncaught TypeError: Cannot read property 'highlight' of undefined

My question is, am I going about this the right way, and if so, how do I get the value of the cell in the "highlight" column and the "row" row?


Solution

  • I needed to wrap the current if statement in another if statement:

    if (typeof data[row] != "undefined") {
      //original if
    }
    

    to make sure the row actually existed