【发布时间】:2015-05-25 18:29:18
【问题描述】:
我正在尝试使特定列的单元格都具有与之关联的data-ip 属性,以便以后在需要数据时可以使用 jQuery 读取它。我可以创建一个单独的隐藏列,其中包含ip,但是我想先尝试这种方法。
我正在尝试将更易读的hostname 列与ip 相关联。这是aoColumns的专栏:
{"sTitle": "Hostname", sName: "host", sWidth: "30%", sClass: 'host', mData:
function (source) {
return source.hostname
}
}
正如您在代码中看到的那样,我有source.hostname,它用JSON hostname 填充td,但是我想应用一个包含source.ip 数据的data-ip 属性。这可能吗?
编辑 - 整个 jQuery 元素:
$('#servicesTable').dataTable({
'aaData': servicesJson['registered_services'],
'aoColumns': [
{"sTitle": "Hostname", sName: "host", sWidth: "30%", sClass: 'host', mData:
function (source) {
return source.hostname
}
},
{"sTitle": "Service", sName: "service", sWidth: "30%", sClass: 'service', mData: "serviceName"},
{"sTitle": "Monitored?", sName: "monitored", sWidth: "10%", sClass: 'monitored', mData:
function (source) {
if (typeof source.active === 'undefined')
return '';
var monitor = source.active;
if (monitor == 1)
return "<input type='checkbox' class='monitor' name='monitored' checked />";
else
return "<input type='checkbox' class='monitor' name='monitored'/>";
}
},
{"sTitle": "Status", sName: "status", sWidth: "15%", sClass: 'status', mData: "status"},
{"sTitle": "URL", sName: "url", sWidth: "5%", sClass: 'url right', mData:
function (source) {
if (typeof source.url === 'undefined' || source.url == '')
return '';
return "<a class='ui-icon ui-icon-link' href='" + source.url + "'>NAGIOS</a>";
}
},
{"sTitle": "Add/Remove", sName: "add-remove-new", sWidth: "15%", sClass: 'add-remove-new', mData:
function (source, type, val) {
if (typeof source.addRemove === 'undefined')
return "<button class='add-remove-new' type='button'>Remove</button>";
else
return "<button class='add-remove-new' type='button'>Add</button>";
}
},
],
'bJQueryUI': true,
'bInfo': false,
'bPaginate': false,
'bSort': false,
'bFilter': true,
'iDisplayLength': 25,
"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
//function that is called everytime an element is added or a redraw is called
//aData[] is an arraw of the values stored in datatables for the row
//to change a row's html use $('td:eq('+index+')', nRow).html( html here ); where index is the index of the td element in the row
}
});
【问题讨论】:
标签: javascript jquery datatables jquery-data