JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//cdn.datatables.net/1.10.5/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="//cdn.datatables.net/1.10.5/css/jquery.dataTables.min.css">
<div id="support-tickets-datatable-view" style="margin-top: 20px;">
<table id="support-tickets-list" class="display" width="100%" cellspacing="0"></table>
</div>
<dd><a href="#" class="view-support-tickets">Refresh</a>
</dd>
JavaScript
function SupportTicketDataTable() {
var self = this;
this.table = $('#support-tickets-list');
this.columnDefs = [{
title: "Ticket ID",
data: "case_ticket_id",
render: function (data, type, row) {
var anchor = $(document.createElement('a'));
anchor.attr("href", "#").text(data);
return anchor.context.outerHTML;
},
targets: [0]
}, {
title: "Status",
data: "status",
width: "65px",
targets: [1]
}, {
title: "Reported By",
data: "case_email",
targets: [2]
}, {
title: "Subject",
data: "case_subject",
targets: [3]
}, {
title: "Description",
data: "case_description",
render: function (data, type, row) {
return self.truncateDescription(data);
},
targets: [4]
}];
}
SupportTicketDataTable.prototype = {
showTable: function (data) {
console.log("I want to render the following data: %o", data);
if ($.fn.DataTable.isDataTable('#support-tickets-list')) {
this.table.DataTable().data = data;
this.table.DataTable().draw();
} else {
this.table.DataTable({
"autoWidth": false,
data: data,
columnDefs: this.columnDefs
});
this.styleDataTablesControls();
}
},
truncateDescription: function (description) {
var retStr = '';
var arr = description.split(' ', 4);
$.each(arr, function (idx, str) {
retStr += str + ' ';
});
retStr += '. . .';
return retStr;
}
};
function devResponse() {
var data = [{
"case_description": "sadasdfsa",
"case_email": "renderer@testexamplesite.com",
"status": "New",
"case_subject": "awsdfads",
"customer_id": null,
"case_ticket_id": "50019000000uIVbAAM"
}, {
...