Rank Column in a JavaScript Server Side DataTable

Rank Column in a JavaScript Server Side DataTable

ghernandezghernandez Posts: 5Questions: 2Answers: 0

The following is my JavaScript Server Side DataTable code:

waitListDataTable = $("#WaitListDataTable").DataTable({
autoWidth: false,
processing: true,
serverSide: true,
dom: "lrtip",
ajax: {
url: '@Url.Action("GetWaitList", "WaitList")',
datatype: "json",
type: "POST"
},
columnDefs: [
{
targets: [2, 3, 9],
visible: false
},
{
targets: [0, 10, 11],
orderable: false,
className: "center",
width: "1%"
}
],
columns: [
{
data: null,
title: "Details",
render: function (row) {
var applicationDetails = '@Url.Action("Details", "Application")/' + row.Id;
return '<a href=\"' + applicationDetails + '\" class=\"btn btn-info\ fa fa-folder-open"></a>';
}
},
{
data: null,
render: function (row) {
if (row.Hrdbid != null) {
return row.Hrdbid;
}
return row.AppNumber;
}
},
{ data: "AppNumber" },
{ data: "Hrdbid" },
{ data: "ApplicationType" },
{ data: "ActivityPhase" },
{
data: "ActivityPhaseDate",
type: "date",
render: function (data) {
var activityPhaseDates = "";
for (var i = 0; i < data.length; i++) {
activityPhaseDates += moment(data[i]).format("MM/DD/YYYY") + " ";
}
return activityPhaseDates;
}
},
{ data: "Address" },
{ data: "Client" },
{ data: "Id" },
{
data: null,
title: "Edit",
render: function (row) {
var applicationEdit = '@Url.Action("Edit", "Application")/' + row.Id;
return '<a href=\"' + applicationEdit + '\" class=\"btn btn-warning\ fa fa-edit"></a>';
}
},
{
data: null,
title: "Delete",
render: function (row) {
var applicationDelete = '@Url.Action("Delete", "Application")/' + row.Id;
return '<a href=\"' + applicationDelete + '\" class=\"btn btn-danger\ fa fa-trash"></a>';
}
}
],
stateDuration: 0,
stateSave: true,
stateSaveCallback: function (settings, data) {
localStorage.setItem(DataTables_${settings.sInstance}, JSON.stringify(data));
},
stateLoadCallback: function (settings) {
return JSON.parse(localStorage.getItem(DataTables_${settings.sInstance}));
}
});

I need to add a Rank column. The Ranking should be done against the AppNumber column, meaning that if AppNumber values are [ "7", "14", "21", "28"], the Ranking values would be ["1", "2", "3", "4"].

I have seen some examples of adding a Ranking column, but they appear to be for client side DataTables.

Replies

  • kthorngrenkthorngren Posts: 16,060Questions: 25Answers: 3,805

    I have seen some examples of adding a Ranking column, but they appear to be for client side DataTables.

    That is correct. All sorting, searching and paging functions are performed by the server side processing script. These features are turned off client side. You will need to create the ranking data in your server script.

    Kevin

  • ghernandezghernandez Posts: 5Questions: 2Answers: 0

    Thank you, Kevin!

Sign In or Register to comment.