datatables.net-plugins
Version:
Various small plug-ins for DataTables including feature, ordering, search and internationalisation plug-ins.
1 lines • 992 B
JavaScript
import jQuery from"jquery";import DataTable from"datatables.net";let $=jQuery;function orderNumbers(e,r){let a=new DataTable.Api(e);a.on("draw.orderNumbers",function(){remove(a,r),draw(a,r)}),a.on("destroy",function(){remove(a,r),a.off("draw.orderNumbers")}),draw(a,r)}function remove(e,r){$("span."+r.className,e.table().header()).remove()}function draw(e,r){var a=e.order();if(1<a.length)for(var o=0;o<a.length;o++){var t=e.column(a[o][0]),n=t.header();t.visible()&&$("<span>").addClass(r.className).text(o+1).appendTo(n)}}function applyOptions(e,r){r&&("boolean"==typeof r?e.enable=r:"object"==typeof r&&(Object.assign(e,r),r.enable||(e.enable=!0)))}$(document).on("init.dt",function(e,r){"dt"===e.namespace&&(applyOptions(e=Object.assign({},orderNumbers.defaults),DataTable.defaults.orderNumbers),applyOptions(e,r.oInit.orderNumbers),e.enable)&&orderNumbers(r,e)}),orderNumbers.defaults={enable:!1,className:"dt-order-number"},DataTable.orderNumbers=orderNumbers;export default DataTable;