Adding classes based on JSON value
Adding classes based on JSON value
richcomptonWF
Posts: 7Questions: 0Answers: 0
I am gearing up to use the JEditable plugin, but have a dilemma. Only certain columns will be editable and it will be determined server side. So I need a way to set the class of that have a value of editable to 'edit' so that those fields become editable. A sample of the JSON is:
[code]
{
"Timeline": [
{
"ID": "1",
"ProjectName": "Project A",
"FocusArea": "Area 01",
"Function": "Task 01",
"ProductGroup": "Group 01",
"Week1": {
"value": "10",
"editable": "false"
},
"Week2": {
"value": "20",
"editable": "false"
},
"Week3": {
"value": "20",
"editable": "false"
},
"Week4": {
"value": "15",
"editable": "true"
}
}
}
]
[/code]
My JS thus far looks like this:
[code]
$(document).ready(function () {
$('#table_id').dataTable({
'bFilter': false,
'bLengthChange': false,
'bProcessing': true,
'bJQueryUI': true,
'sPaginationType': 'full_numbers',
"sDom": 'ript',
'sAjaxSource': 'testData.json',
'sAjaxDataProp': 'Timeline',
'aoColumns': [
{'mData': 'ID', 'bVisible': false},
{'mData': 'Week1.editable'},
{'mData': 'Week2.editable', 'bVisible': false},
{'mData': 'Week3.editable', 'bVisible': false},
{'mData': 'Week4.editable'},
{'mData': 'ProjectName'},
{'mData': 'FocusArea'},
{'mData': 'Function'},
{'mData': 'ProductGroup'},
{'mData': 'Week1.value'},
{'mData': 'Week2.value'},
{'mData': 'Week3.value'},
{'mData': 'Week4.value'}
],
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
var calculateTotal = function(column) {
var total = 0;
for(var i = 0; i
[code]
{
"Timeline": [
{
"ID": "1",
"ProjectName": "Project A",
"FocusArea": "Area 01",
"Function": "Task 01",
"ProductGroup": "Group 01",
"Week1": {
"value": "10",
"editable": "false"
},
"Week2": {
"value": "20",
"editable": "false"
},
"Week3": {
"value": "20",
"editable": "false"
},
"Week4": {
"value": "15",
"editable": "true"
}
}
}
]
[/code]
My JS thus far looks like this:
[code]
$(document).ready(function () {
$('#table_id').dataTable({
'bFilter': false,
'bLengthChange': false,
'bProcessing': true,
'bJQueryUI': true,
'sPaginationType': 'full_numbers',
"sDom": 'ript',
'sAjaxSource': 'testData.json',
'sAjaxDataProp': 'Timeline',
'aoColumns': [
{'mData': 'ID', 'bVisible': false},
{'mData': 'Week1.editable'},
{'mData': 'Week2.editable', 'bVisible': false},
{'mData': 'Week3.editable', 'bVisible': false},
{'mData': 'Week4.editable'},
{'mData': 'ProjectName'},
{'mData': 'FocusArea'},
{'mData': 'Function'},
{'mData': 'ProductGroup'},
{'mData': 'Week1.value'},
{'mData': 'Week2.value'},
{'mData': 'Week3.value'},
{'mData': 'Week4.value'}
],
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {
var calculateTotal = function(column) {
var total = 0;
for(var i = 0; i
This discussion has been closed.
Replies
[code]
{
"Timeline": [
{
"DT_RowId" : "1",
"DT_RowClass" : "highlight",
"ID": "1",
"ProjectName": "Project A",
[/code]
http://datatables.net/release-datatables/examples/server_side/ids.html
Allan
[code]
{'mData': 'Week1.value', 'sClass': 'Week1.editable'},
[/code]
where Week1.editable = the JSON value.
The whole column either would be editable or not so that would work but I haven't had any luck getting it to read the value vs just reading Week1.editable as a string.