Custom JavaScript Date Time Sorter and Date Time Formatter Function For Bootstrap Table in ASP.NET MVC Using Moment.JS
Hello Fellow Developers,
function DateTimeFormatter(value, row, index) { if (value === null || value === undefined || value === "") { return ""; } else { return moment(value).format('YYYY-MM-DD HH:mm:ss'); } }
function DateTimeSorter(a, b) { var dateA = new Date(moment(a).format('YYYY-MM-DD HH:mm:ss')); var dateB = new Date(moment(b).format('YYYY-MM-DD HH:mm:ss')); if (dateA < dateB) return -1; if (dateA > dateB) return 1; return -0; }
<th data-field="LastLogin" data-sortable="true" data-sorter="DateTimeSorter" data-formatter="DateTimeFormatter" data-searchable="true">Last Login</th>
Comments
Post a Comment