Reactjs ag网格:接近到期日期时的彩色单元格
如果网格上的日期即将到期,即“Survey Exp-1/1/2020”,则尝试为单元格着色,我希望当今天的日期在供应商到期的5个月内时,单元格变为红色。请帮忙Reactjs ag网格:接近到期日期时的彩色单元格,reactjs,ag-grid-react,Reactjs,Ag Grid React,如果网格上的日期即将到期,即“Survey Exp-1/1/2020”,则尝试为单元格着色,我希望当今天的日期在供应商到期的5个月内时,单元格变为红色。请帮忙 var today = new Date(); var curr_date = today.getDate(); var curr_month = today.getMonth() + 1; var curr_year = today.getFullYear();
var today = new Date();
var curr_date = today.getDate();
var curr_month = today.getMonth() + 1;
var curr_year = today.getFullYear();
var todayMan = curr_month + '/' + curr_date + '/' curr_year
class Bsall extends React.Component {
constructor(props) {
super(props)
this.state = {
items: [],
columnDefs: [
{headerName: "Supplier Status", field: "supplier_status", sortable: true, filter: true},
{headerName: "Survey Exp", field: "survey_exp", sortable: true, filter: true, cellStyle:
params => {
if (params.value < todayMan + 5) {
return {'background-color': 'red'}}
}},
为了达到预期的结果,请使用下面的选项使用新日期并将月份与getMonth from Date进行比较 从两个日期获得年差,并乘以12转换为月 new Dateval.getFullYear-new DatetodayMan.getFullYear*12 通过getMonth方法获取两个日期的月份及其差值 new Dateval.getMonth-new DatetodayMan.getMonth 将两者结合起来将给出日期之间的月数 检查是否少于5个月,并应用样式 如果月份<5{ 返回{'background-color':'red'} }
工作代码示例供参考-您不能添加todayMan+5,它将变为1957/11/20195您知道可以做些什么吗?