Author Topic: Conditional Formating of past due record  (Read 3838 times)

neoinbiz

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 22
    • View Profile
Conditional Formating of past due record
« on: August 01, 2019, 06:47:39 pm »
How do I go about setting the DueDate in "RED" when the Date value for Due Date is past

Code: [Select]
obj.colModel = [

{ title: "ID", hidden: true, dataIndx: "ID" },
        { title: "", minWidth: 27, width: 27, type: "detail", resizable: false, editable: false, exportRender: false  /* no need to mention dataIndx */ },
{ title: "Task Name Name", width: 250, dataIndx: "Title", exportRender: false,
filter: { crules: [{ condition: 'contain' }],
/* filter: { type: "textbox",
        condition: 'contain',
        listeners: ['keyup']*/
     },
     render: function(ui) {
      return "<a href='" + thisWebUrl + "/Lists/" + listName + "/" + formName + ".aspx?ID=" + ui.rowData.ID + "&Source=" + encodeURIComponent(returnPage) + "'>" + ui.cellData + "</a>";
    }
},

{ title: "Assigned Date", width: 155, align:"center", dataIndx: "StartDate",
filter: { crules: [{ condition: 'equal' }],
}
},
{ title: "Due from Assigned", width: 165, align:"center", dataIndx: "DueDate",
filter: { crules: [{ condition: 'equal' }],
}
},
{ title: "Suspense Date", width: 155,align:"center",  dataIndx: "FinalReportDate",
filter: { crules: [{ condition: 'equal' }],
}
},

{ title: "Completed", width: 110, align:"center", dataIndx: "PercentComplete",
filter: { crules: [{ condition: 'equal' }],
     }
},
{ title: "Assigned From", width: 155, align:"center", dataIndx: "AssignedFrom",
filter: { crules: [{ condition: 'equal' }],
    }
},

{ title: "Primary Assigned To", width: 155, align:"center", dataIndx: "PrimaryAssignedTo",
filter: { crules: [{ condition: 'equal' }],
     },
},
{ title: "Task Description", width: 275, dataIndx: "TaskSummaryDescription",
filter: { crules: [{ condition: 'contain' }],
     },
/*Tippy code Step 1 */
     render: function(ui) {
      if(ui.cellData) {
          return "<span class='tippy-desc' data-tippy-content='" + ui.cellData + "'>" + ui.cellData.substr(0,25) + "...</span>";
      }
    }
}
];



paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Conditional Formating of past due record
« Reply #1 on: August 01, 2019, 10:29:38 pm »
Date values in the column should be in native js format.

Code: [Select]
render: function(ui){
var dt = new Date();

        //new Date(ui.cellData) is date value of cell
        // new Date(dt.getFullYear(), dt.getMonth(), dt.getDate()) is date value for today ( excluding time ).

if( new Date(ui.cellData) < new Date(dt.getFullYear(), dt.getMonth(), dt.getDate()) ){
return {style:"color:red;"} //add style to the cell.
}
},
« Last Edit: August 01, 2019, 10:37:04 pm by paramvir »

neoinbiz

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Conditional Formating of past due record
« Reply #2 on: August 01, 2019, 10:33:12 pm »
Thank you for you quick response.
Can you explain a little what the code is actually doing?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Conditional Formating of past due record
« Reply #3 on: August 01, 2019, 10:39:28 pm »
I've added comments to code in previous post. For more details please check API docs and demos for column.render callback and js Date() function.

neoinbiz

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Conditional Formating of past due record
« Reply #4 on: August 02, 2019, 12:10:07 am »
I followed as indicated but there are no results and I have 8 dates I know are past due
Am I missing something?


Code: [Select]
[/ { title: "Assigned Date", width: 155, align:"center", dataIndx: "StartDate",
filter: { crules: [{ condition: 'equal' }],
render: function(ui){
var dt = new Date();

        //new Date(ui.cellData) is date value of cell
        // new Date(dt.getFullYear(), dt.getMonth(), dt.getDate()) is date value for today ( excluding time ).

if( new Date(ui.cellData) < new Date(dt.getFullYear(), dt.getMonth(), dt.getDate()) ){
return {style:"color:red;"} //add style to the cell.
}
},
}
},
code]

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Conditional Formating of past due record
« Reply #5 on: August 02, 2019, 08:51:03 am »
What is the format of the dates. Please share sample data.

neoinbiz

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Conditional Formating of past due record
« Reply #6 on: August 02, 2019, 08:53:13 am »
07/31/2019

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Conditional Formating of past due record
« Reply #7 on: August 02, 2019, 01:21:16 pm »
works fine in demo: https://paramquery.com/pro/demos/filter_header_local

can be verified by adding same render callack in OrderDate column.

Which version of grid are you using?

Please share a jsfiddle if still facing issues.

neoinbiz

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Conditional Formating of past due record
« Reply #8 on: August 02, 2019, 07:19:36 pm »
Here is how I placed render code in the demo link and nothing changes color.
I tried fiddler but the entire preview pane is white so not sure why nothing ran on there.


Code: [Select]
    { title: "Order Date", minWidth: "190", dataIndx: "OrderDate", dataType: "date",
        filter: { crules: [{ condition: "between" }],
render: function(ui){
var dt = new Date();

//new Date(ui.cellData) is date value of cell
// new Date(dt.getFullYear(), dt.getMonth(), dt.getDate()) is date value for today ( excluding time ).

if( new Date(ui.cellData) < new Date(dt.getFullYear(), dt.getMonth(), dt.getDate()) ){
return {style:"color:red;"} //add style to the cell.
}
},

}
    },

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Conditional Formating of past due record
« Reply #9 on: August 05, 2019, 04:20:13 pm »
Your syntax is incorrect. Please add render callback to the column instead of column.filter
« Last Edit: August 05, 2019, 04:23:51 pm by paramvir »