Devextreme-reactive: Alternate color row with Tree data

Created on 5 Oct 2018  路  2Comments  路  Source: DevExpress/devextreme-reactive

Is it possible to alternate color row in the virtual table with Tree data?

I added a persistent row index to identify a row bud it is no best solution:
https://codesandbox.io/s/yv1wopw239

Are you a workaround?
Carlo

question

Most helpful comment

Hi,

Let's take a look at your example.
The following line adds a row index for each row:

const dataWithRowIndex = data ? rows.map((row, index) => ({ ...row, rowIndex: index })) : data;

Then, you pass the聽dataWithRowIndex聽array to the聽rows聽property of the聽Grid聽component. Next, you use the聽CustomTreeData聽plugin. As you can see in our聽documentation, the聽CustomTreeData plugin modifies Grid rows. That's why your row indices don't make sense. At the same time, the聽TableTreeColumn plugin聽exports聽the聽tableBodyRows聽Getter, which contains rows that will be rendered. Thus, you can override this Getter to apply a row index:

const tableBodyRowsComputed = ({ tableBodyRows }) =>
  tableBodyRows.map((tableBodyRow, i) => ({
    ...tableBodyRow,
    ROW_INDEX: i
  }));

<Getter name="tableBodyRows" computed={tableBodyRowsComputed} />

Then, you can use the聽ROW_INDEX聽field to highlight odd rows.

I've聽updated聽your sample as well.

All 2 comments

Hi,

Let's take a look at your example.
The following line adds a row index for each row:

const dataWithRowIndex = data ? rows.map((row, index) => ({ ...row, rowIndex: index })) : data;

Then, you pass the聽dataWithRowIndex聽array to the聽rows聽property of the聽Grid聽component. Next, you use the聽CustomTreeData聽plugin. As you can see in our聽documentation, the聽CustomTreeData plugin modifies Grid rows. That's why your row indices don't make sense. At the same time, the聽TableTreeColumn plugin聽exports聽the聽tableBodyRows聽Getter, which contains rows that will be rendered. Thus, you can override this Getter to apply a row index:

const tableBodyRowsComputed = ({ tableBodyRows }) =>
  tableBodyRows.map((tableBodyRow, i) => ({
    ...tableBodyRow,
    ROW_INDEX: i
  }));

<Getter name="tableBodyRows" computed={tableBodyRowsComputed} />

Then, you can use the聽ROW_INDEX聽field to highlight odd rows.

I've聽updated聽your sample as well.

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

slava-lu picture slava-lu  路  3Comments

cavr picture cavr  路  3Comments

bloolizard picture bloolizard  路  3Comments

linuxhype picture linuxhype  路  3Comments

stclairdaniel picture stclairdaniel  路  3Comments