簡體   English   中英

如何更改react-table中單行的邊框顏色

[英]How to change the border color of a single row in react-table

我知道如何更改ReactTable object 中一行的背景顏色(代碼如下)。

如何更改行邊框的顏色(不是整個表格的邊框)? 我嘗試將以下代碼中的background替換為border-colorborderColorborder ,但這些選項都不起作用——或者,我得到一個錯誤,或者在編譯時什么也沒有發生。

getTrProps={(state, rowInfo, column) => {
    if(rowInfo) {
        return {
            style: {
                background: "blue"
            }
        };
    }
    return {}; 
}

像這樣:

getTrProps = (state, rowInfo, instance) => {
    if (rowInfo) {
      return {
        style: {
          border: rowInfo
            ? rowInfo.row.age >= 20
              ? "solid 1px black"
              : "none"
            : "none"
        }
      };
    }
    return {};
  };

工作示例: https://codesandbox.io/s/react-table-gettrprops-ijgzy

按照此操作根據 row.value 條件更改單個單元格顏色

{
  Header: () => <div className="text-center font-weight-bold">Status</div>,
  accessor: "selectedstatus",
  className: "font",
  width: 140,
  Cell: (row) => (
    <div
      className="text-center h-6"
      style={{ background: row.value === "Selected" ? "green" : "red" }}
    >
      {row.value}
    </div>
  ),
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM