下午好,我已填充数据表(jQuery的表格插件)从WCF服务检索到的数据,它有它有一个链接,做工不错列defaultContent,但现在我需要创建和使用取决于另一个链接额外defaultContent列一个if条件,如下所示
if (tipo_evento == 3213) { ... add a defaultContent...}
我曾尝试添加了如果下面的代码,但它是不可能的,你能告诉我如何添加额外的列?这是我的表的代码
function cargarTabla() {
$('#myTable').DataTable({
searching: false,
paging: false,
responsive: true,
ordering: false,
bInfo: true,
bLengthChange: false,
processing: true,
info: true,
deferRender: true,
orderMulti: false,
bAutoWidth: false,
"ajax": {
"url": "/Home/CargarTabla?id=" + noDocumento + "&grupo=" + grupoDT,
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "nombres", "autoWidth": false, "orderable": false, "sClass": "alignRight", "sWidth": "18%" },
{ "data": "apellidos", "autoWidth": false, "orderable": false, "sClass": "alignRight", "sWidth": "18%" },
{ "data": "dui", "autoWidth": false, "orderable": false, "sClass": "alignRight", "sWidth": "5%" },
{ "data": "numero_isss", "autoWidth": false, "orderable": false, "sClass": "alignRight", "sWidth": "5%" },
{ "data": "cargo_participante", "autoWidth": false, "orderable": false, "sClass": "alignRight", "sWidth": "20%" },
{ "data": "genero", "autoWidth": false, "orderable": false, "visible": false },
{ "data": "nivel_puesto", "autoWidth": false, "orderable": false, "visible": false },
{ "data": "grupo", "autoWidth": false, "orderable": false, "visible": false },
{ "defaultContent": " <a href='#' id='select'>Sustituir</a> ", "autoWidth": true, "orderable": false, "sClass": "alignRight", "sWidth": "5%" }
],
"oLanguage": {
"sEmptyTable": "No hay registros disponibles",
"sInfo": " _TOTAL_ registros. Mostrando de (_START_ a _END_)",
"sLoadingRecords": "Por favor espera - Cargando...",
"sSearch": "Filtro:",
"sLengthMenu": "Mostrar _MENU_",
"oPaginate": {
"sLast": "Última página",
"sFirst": "Primera",
"sNext": "Siguiente",
"sPrevious": "Anterior"
},
"oAria": {
"sSortAscending": ": Activar para ordenar la columna de manera ascendente",
"sSortDescending": ": Activar para ordenar la columna de manera descendente"
}
}
});
}
我只是说从Gyrocode.com这个代码,andit工作得很好,但刚刚添加的列占据太多的空间在我的表,如何添加“autoWidth”:真实的,“订购”:假“的sclass”:“alignRight” “sWidth”: “5%”?
"render": function (data, type, full, meta) {
if (type === 'display') {
if (tipo_evento == 3213) {
data = " <a href='#' id='Teliminar'>Eliminar</a> " +"|"+ " <a href='#' id='select'>Sustituir</a> ";
} else {
data = " <a href='#' id='select'>Sustituir</a> ";
}
}
return data;
使用columns.render
选项为一个单元格的内容。
例如,为了基于tipo_evento
变量的值生成内容:
{
"render": function(data, type, full, meta){
if(type === 'display'){
if(tipo_evento == 3213){
data = "";
} else {
data = " <a href='#' id='select'>Sustituir</a> ";
}
}
return data;
},
// ... other options ...
"autoWidth": true,
"orderable": false,
"sClass": "alignRight",
"sWidth": "5%"
}