react-bootstrap-table icon indicating copy to clipboard operation
react-bootstrap-table copied to clipboard

Dynamic row background colour

Open romil-zealous opened this issue 9 years ago • 8 comments

Hi Allen,

I want to assign row background color as dynamic such as colour code is retrieving from the database table. I want to also provide a different row highlight colour when it is selected with checkbox. So, when I de-select any row, it should retain the old colour (which I have set dynamically)

Can you please let me know how to achieve this?

Cheers, Romil

romil-zealous avatar Mar 03 '17 14:03 romil-zealous

I want to assign row background color as dynamic such as colour code is retrieving from the database table

https://github.com/AllenFang/react-bootstrap-table/blob/master/examples/js/style/tr-class-function-table.js#L24

I want to also provide a different row highlight colour when it is selected with checkbox.

we can only assign a string color code in selectRow.bgColor and I think I can support this to accept a function to have more flexibility.

AllenFang avatar Mar 03 '17 15:03 AllenFang

Is there any update on this issue?

Kind Regards, Anika

anikakalbrun avatar Mar 20 '17 09:03 anikakalbrun

@anikakalbrun, sorry I'm really busy in this couples weeks, I'll do it ASAP.

AllenFang avatar Mar 26 '17 06:03 AllenFang

Hey @AllenFang , thanks for the update. I am looking forward for that feature to be implemented.

anikakalbrun avatar Mar 29 '17 20:03 anikakalbrun

Fixed on v3.1.4, please have a look and check this for example, thanks.

AllenFang avatar Apr 01 '17 11:04 AllenFang

Thanks @AllenFang, this works perfectly for me. Great Job!

anikakalbrun avatar Apr 03 '17 11:04 anikakalbrun

Tip: If you can't use class and need to use style (I got the tr color from my back end for example) there is also trStyle.

https://github.com/AllenFang/react-bootstrap-table/blob/master/examples/js/style/tr-style-table.js

Ogglas avatar Dec 25 '17 20:12 Ogglas

Have been trying for quite a while and this puzzles me quite a bit.

getTrProps={(state, rowInfo, column, instance) => {
  return {
    onClick: (e, handleOriginal) => {
      console.log('A Td Element was clicked!')
      console.log('it produced this event:', e)
      console.log('It was in this column:', column)
      console.log('It was in this row:', rowInfo.original.transactionStatus)
      console.log('It was in this table instance:', instance)

      // IMPORTANT! React-Table uses onClick internally to trigger
      // events like expanding SubComponents and pivots.
      // By default a custom 'onClick' handler will override this functionality.
      // If you want to fire the original onClick handler, call the
      // 'handleOriginal' function.
      if (handleOriginal) {
        handleOriginal()
      }
    },
    style: {
      background: ((rowInfo.original.transactionStatus == "settled") ? "tableHighlight": "" )
    }
  }
}}

When I console log "'It was in this row:', rowInfo.original.transactionStatus", it works.

However once I add the styles, calling the same "rowInfo.original.transactionStatus". It gives me the error of "Uncaught TypeError: Cannot read property 'original' of undefined".

This should be easy but I can't seem to see where the error lies.

tonychew1986 avatar Mar 08 '18 16:03 tonychew1986