I would like to highlight the rows which are having previous date by comparing with most recent date from the DataTable Column.
Please advise. Thanks in advance!
I would like to highlight the rows which are having previous date by comparing with most recent date from the DataTable Column.
Please advise. Thanks in advance!
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satish BingiPosted Nov 27, 2023, 3:36 PM
Thanks for your quick support!
Here, I tried with the below code which is working fine.
Howevr, in the date place ('9/8/2000') I want to call the max date variable, so that all the rows except max date will highlight.
"targets": [0],
"createdCell": function (td, cellData, rowData, row, col) {
debugger;
if (cellData < '9/8/2000') {
var rowIndex = row + 1;
$($('#tblData tbody tr:nth-child(' + rowIndex + ')')).addClass('highlight');
}
}
Sam HobbsPosted Nov 25, 2023, 1:02 AM
Your code has:
maxCell.addClass('highlight');maxCell is set to $(this) but I do not know what $(this) is. The name maxCell implies it is a cell. You say you want an entire row to be Red but you are only getting a single cell highlighted. I assume that highlighted means Red. The only place I see the color Red is for the highlight class. If you are setting only a cell to have that class then you are getting only a cell with that class.
Satish BingiPosted Nov 24, 2023, 5:35 PM
I tried with the below.. however, it's highlighting only one cell instead of entire row and the other rows with older dates
@foreach (var item in Model)
{
@Html.DisplayFor(model => item.birthDate)
@Html.DisplayFor(modelItem => item.name)
@Html.DisplayFor(modelItem => item.group)
$(function (td, cellData, rowData, row, col) {
var maxCell = undefined;
var maxVal = undefined;
$('.dateRow').each(function () {
var that = $(this);
var dt = new Date(that.text());
if (!maxCell || dt < maxVal) {
maxCell = that;
maxVal = dt;
}
});
maxCell.addClass('highlight');
});
.highlight {
background-color: red;
}
Amit MohantyPosted Nov 24, 2023, 12:31 PM
Still not clear. What is the logic behing it and explain what you have done till now?
Satish BingiPosted Nov 24, 2023, 11:04 AM
Here is the output I am looking for.
Amit MohantyPosted Nov 24, 2023, 9:34 AM
Could you clarify your question more concisely with some example and please explain what you have accomplished so far?