Row Group Styling Issue
Row Group Styling Issue
Hello,
So I thought that my row styling with statusColor was working fine. It appears whatever the most recent item added to the DataTable's status is, it styles the group row based off of the most recent item. So in my example, the current day is Wednesday, it is only going to read the day status for the Wednesday cells, which has 3 status which should be red (PTO & H), two status which should be green (P) and one status which should be yellow (NR). It is going to style the group row Green because that is the last/most recent object in the data set. In essence, it should style the group row "Red" because there are more "red" statuses than "green" or "yellow"
This question has accepted answers - jump to:
Answers
The problem is your loop is setting the
statusClass
each time through the loop so the last one will be the one applied. In your loop you will need to count each status then once the loop is complete set thestatusClass
to the highest count.Here is some pseudo code:
Kevin
Updated test case: https://jsfiddle.net/BeerusDev/mznL52p8/57/
I thought this would work, but it gives no errors and nothing the statusClass doesn't get added to the row.
Line 19 should be initialized before the loop (before line 2). Otherwise you are resetting the values each time through the loop. The
console.log(counter);
in line 29 should show this is happening.The if statements aren't going to work, they need to look like this:
Also the if statements lines 30-38 should come after the loop - between lines 40 and 41.
Kevin
So I have encountered an unexpected error, which is good because it is very possible to be a case that could happen. So if I have a group where the child rows have 2 green todayStatus and 2 yellow todayStatus, it will even out and no class will be added to the group row, resulting in it staying grey.
I have been suggested to use percentages instead, which I have never really worked with before in JS.
I came up with part of a potential solution, after the counter++ if statements, could I do this?
On my actual implmentation, it does the styling but I do not think it is correct, then when I update my Fiddle to match the code, it console.logs() NaN. https://jsfiddle.net/BeerusDev/mznL52p8/63/
You can handle this with percentages (not sure what the result of your code snippet will be - you will need to test it) or you can put in conditions that will handle the ties and other cases or you can default
statusClass
to a color and if none of the conditions are met it will be the default color.The logic you choose is up to your specific requirements. The code to apply that logic is standard Javascript and outside of Datatables functionality. A better place for Javascript help is to search Stack Overflow for ideas of how to code what you want.
Kevin
It seems to work at first, but it actually isn't. I just created a question on SO so hopefully someone can help me there.
But here is the result of my proposed snippet https://jsfiddle.net/BeerusDev/mznL52p8/75/
IT appears as if I only include:
it works, here is my test case: https://jsfiddle.net/BeerusDev/mznL52p8/82/
UPDATE it doesn't work. If you see the HR dropdown you can tell