React-table: Align component in cell

Created on 24 Jan 2018  路  6Comments  路  Source: tannerlinsley/react-table

What version of React-Table are you using?

6.7.6

What bug are you experiencing, or what feature are you proposing?

Can not align component within the cell.

Most helpful comment

Check this out: https://codesandbox.io/s/ojyx80ljo5
I've added the property className and defined the CSS class in index.css.

index.js:

                {
                  Header: "Last Name",
                  id: "lastName",
                  accessor: d => d.lastName,
                  className: "right"
                }

index.css:

.right {
  text-align: right;
}

All 6 comments

Check this out: https://codesandbox.io/s/ojyx80ljo5
I've added the property className and defined the CSS class in index.css.

index.js:

                {
                  Header: "Last Name",
                  id: "lastName",
                  accessor: d => d.lastName,
                  className: "right"
                }

index.css:

.right {
  text-align: right;
}

If you want the Column name to be aligned right

Header: () => (
    <div style={{
        textAlign: "right"
    }}>
        Actions
      </div>
)

@DamianFekete @parwat08 both your solutions align the text in the table header,
i'd bet @M1chaelChen was referring to aligning the values, and that's done diffrently:

https://codesandbox.io/s/ow23qwv39

@robertvasile, my proposal works OK. Check the green values/cells: https://codesandbox.io/s/ryj15q8wyq , they are right-aligned.

@parwat08 already said that her/his change it is for the column name, not the values. That may be useful if you want to align everything, not only values.

@DamianFekete Thanks mate

@robertvasile Mine solution might be useful if someone wants to align the column name. I already have mentioned it.

I found this very helpful to align the components within all the cells in the table:
getTdProps={() => ({
style: {
textAlign: 'right'
}
})}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexanderwhatley picture alexanderwhatley  路  3Comments

dilipsundarraj1 picture dilipsundarraj1  路  3Comments

mellis481 picture mellis481  路  3Comments

Abdul-Hameed001 picture Abdul-Hameed001  路  3Comments

krishna-shenll picture krishna-shenll  路  3Comments