Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

javascript - 突出显示MUI数据表中的行(Highlight rows in MUI-Datatables)

I created a simple table using React.js and MUI-Datatables :

(我使用React.js和MUI-Datatables创建了一个简单的表:)

import MUIDataTable from "mui-datatables";

const columns = ["Name", "Company", "City", "State"];

const data = [
 ["Joe James", "Test Corp", "Yonkers", "NY"],
 ["John Walsh", "Test Corp", "Hartford", "CT"],
 ["Bob Herm", "Test Corp", "Tampa", "FL"],

 ["James Houston", "Test Corp", "Dallas", "TX"],
];

const options = {
  filterType: 'checkbox',
};

<MUIDataTable
  title={"Employee List"}
  data={data}
  columns={columns}
  options={options}
/>

How can I add a custom CSS class to a single row inside the table.

(如何将自定义CSS类添加到表中的单行中。)

Lets say I want the second row with John Walsh to have a green background color.

(可以说,我希望John Walsh的第二行具有绿色背景色。)

  ask by Klaus translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just as a suggestion, i hope you get my idea :

(只是建议,我希望你能明白我的意思:)

For the CSS Part :

(对于CSS部分:)

.highlightRow {
  background-color :green;
}

highlight rows using react render

(使用react render突出显示行)

hasTobeHighlighted : function(data) {
      const isHovered = isSelected;
       for(var i=0; i< data.length;i++){
            if(data[i].includes('John Walsh'))
             return "highlightRow ";
       }

      return "";
    }

rows = React.createClass({
render: function() {
return ( 
      <MUIDataTable  title={"Employee List"}  data={data}  columns={columns}
       options={options} className={hasTobeHighlighted } />
       );
  }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...