Skip to content

Commit

Permalink
color formatting for all columns of assignments table
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruborcalor committed Feb 9, 2019
1 parent c3b8565 commit a43af60
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
42 changes: 42 additions & 0 deletions public/extraFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,48 @@ function getColor(gradeToBeColored) {
}
}

function getLightColor(gradeToBeColored) {
if (parseFloat(gradeToBeColored) >= 90) {
return "#99ff66";
} else if (parseFloat(gradeToBeColored) >= 80) {
return "#66ccff";
} else if (parseFloat(gradeToBeColored) >= 70) {
return "#ffff66";
} else if (parseFloat(gradeToBeColored) >= 60) {
return "#ff8533";
} else if (parseFloat(gradeToBeColored) >= 0) {
return "#ff4d4d";
} else {
return "white";
}
}

let rowFormatter = function(cell, formatterParams) {
let numberGrade = parseFloat(cell.getValue());
let rowColor = cell.getRow().getData().color;

let value = cell.getValue();
return "<span style='color:" + rowColor + "; font-weight:bold;'>" + value + "</span>";


}

let rowGradeFormatter = function(cell, formatterParams) {
let numberGrade = parseFloat(cell.getValue());
let rowColor = cell.getRow().getData().color;


if (isNaN(numberGrade)) {
return "No Grade";

} else {
let value = parseFloat(cell.getValue()) + "% " + getLetterGrade(cell.getValue());
return "<span style='color:"+rowColor+"; font-weight:bold;'>" + value + "</span>";

}

}

let gradeFormatter = function(cell, formatterParams) {
let numberGrade = parseFloat(cell.getValue());

Expand Down
19 changes: 9 additions & 10 deletions public/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@ <h4 id="title">Aspine</h4>
//height:205, // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
//data:tabledata[0].assignments, //assign data to table
layout:"fitColumns", //fit columns to width of table (optional)
rowFormatter:function(row) {
//if(row.getData().col == "blue"){
row.getElement().style.backgroundColor = row.getData().color;
//}
},
//rowFormatter:function(row) {
// row.getElement().style.backgroundColor = row.getData().color;
//},
columns:[ //Define Table Columns
{title:"Assignment", field:"name", editor:"input"},
{title:"Assignment", field:"name", editor:"input", formatter: rowFormatter,},
{title:"Category", field:"category", editor:"select",
editorParams:function(cell) {
console.log(tableData.classes[selected_class_i].categories);
return {values:Object.keys(tableData.classes[selected_class_i].categories)};
}
},
formatter: rowFormatter,
},
{title:"Score", field:"score", editor:"number", editorParams:{min:0, max:100, step:1,}},
{title:"Max Score", field:"max_score", editor:"number", editorParams:{min:0, max:100, step:1,}},
{title:"Percentage", field: "percentage", formatter: gradeFormatter},
{title:"Score", field:"score", editor:"number", editorParams:{min:0, max:100, step:1,}, formatter: rowFormatter,},
{title:"Max Score", field:"max_score", editor:"number", editorParams:{min:0, max:100, step:1,}, formatter: rowFormatter,},
{title:"Percentage", field: "percentage", formatter: rowGradeFormatter},
],
});
//create Tabulator on DOM element with id "example-table"
Expand Down

0 comments on commit a43af60

Please sign in to comment.