I'm working on a DataTable that has buttons to choose what to do with each row. However, the buttons vary based on the string value of another one of the cells. This is the code I use to populate the tables:
var table = $('#CheckRegisterTable').dataTable({
'ajax': {
type: 'POST',
url: '@Url.Action("GetData", "CheckRegister")',
//data: function (d) {
//}
},
columns: [
{
data: "select",
render: function ( data, type, row ) {
if ( type === 'display' ) {
return '<input type="checkbox" class="editor-active">';
}
return data;
},
sortable: false,
className: "text-center"
},
{
data: 'checkNo',
sortable: true,
className: "text-center"
},
{
data: 'studentID',
sortable: true,
className: "text-center"
},
{
data: 'ssn',
sortable: true,
className: "text-center"
},
{
data: 'payee',
sortable: true,
className: "text-center"
},
{
data: 'date',
sortable: true,
className: "text-center"
},
{
data: 'type',
sortable: true,
className: "text-center"
},
{
data: 'amount',
sortable: true,
className: "text-right"
},
{
data: 'status',
sortable: true,
className: "text-center"
},
{
render: function (data) {
var row = table.row($(this).parents('tr')).data();
if (row[8] == "Printed") {
return '<button><i class="fa-fa-reply"></button><i class="fa-fa-rotate-left"><button><i class="fa-fa-close"></button><button><i class="fa-fa-print"></button><button><i class="fa-fa-info"></button>'
}
else if (row[8] == "Cleared") {
return '<button><i class="fa-fa-info"></button>'
}
else if (row[8] == "Stopped") {
return '<button><i class="fa-fa-rotate-left"></button><button><i class="fa-fa-close"></button><button><i class="fa-fa-info"></button>'
}
else if (row[8] == "Reissued") {
return '<button><i class="fa-fa-reply"></button><button><i class="fa-fa-rotate-left"></button><button><i class="fa-fa-close"></button><button><i class="fa-fa-info"></button>'
}
else if (row[8] == "Returned") {
return '<button><i class="fa-fa-rotate-left"></button><button><i class="fa-fa-info"></button>'
}
else if (row[8] == "Reissue Pending") {
return '<button><i class="fa-fa-rotate-left"></button><button><i class="fa-fa-info"></button>'
}
else if (row[8] == "Stop Pending") {
return '<button><i class="fa-fa-close"></button><button><i class="fa-fa-info"></button>'
}
}
}
],
ordering: true,
order: [0, 'Name'],
processing: true,
serverSide: true
});
But the code is giving me errors, and I'm not even sure I'm doing it right. What's the best way to look at the value in the 'status' column and populate the other column with the buttons? Thanks for your help!
Aucun commentaire:
Enregistrer un commentaire