/*! DataTables Amaze UI 2.x integration */ /** * DataTables integration for Amaze UI 2.x. This requires Amaze UI 2.x and * DataTables 1.10 or newer. */ 'use strict'; var $ = require('jquery'); var DataTable = require('datatables'); // language // https://github.com/DataTables/Plugins/blob/master/i18n/Chinese.lang DataTable.defaults.oLanguage = { sProcessing: "处理中...", sLengthMenu: "显示 _MENU_ 项结果", sZeroRecords: "没有匹配结果", sInfo: "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项", sInfoEmpty: "显示第 0 至 0 项结果,共 0 项", sInfoFiltered: "(由 _MAX_ 项结果过滤)", sInfoPostFix: "", sSearch: "搜索:", sUrl: "", sEmptyTable: "表中数据为空", sLoadingRecords: "载入中...", sInfoThousands: ",", oPaginate: { sFirst: "首页", sPrevious: "上页", sNext: "下页", sLast: "末页" }, oAria: { sSortAscending: ": 以升序排列此列", sSortDescending: ": 以降序排列此列" } }; // Set the defaults for DataTables initialisation // https://datatables.net/reference/option/dom $.extend(true, DataTable.defaults, { dom: "<'am-g am-datatable-hd'<'am-u-sm-6'l><'am-u-sm-6'f>>" + "<'am-g'<'am-u-sm-12'tr>>" + "<'am-g am-datatable-footer'<'am-u-sm-5'i><'am-u-sm-7'p>>", renderer: 'amazeui' }); /* Default class modification */ $.extend(DataTable.ext.classes, { /* Features */ sWrapper: 'dataTables_wrapper am-datatable am-form-inline dt-amazeui', sFilter: 'dataTables_filter am-datatable-filter', sFilterInput: 'am-form-field am-input-sm', sInfo: 'dataTables_info am-datatable-info', sPaging: 'dataTables_paginate paging_', /* Note that the type is postfixed */ sLength: 'dataTables_length am-form-group am-datatable-length', sLengthSelect: 'am-form-select am-input-sm', sProcessing: "dataTables_processing", /* Sorting */ sSortAsc: "sorting_asc", sSortDesc: "sorting_desc", sSortable: "sorting", /* Sortable in both directions */ sSortableAsc: "sorting_asc_disabled", sSortableDesc: "sorting_desc_disabled", sSortableNone: "sorting_disabled", sSortColumn: "sorting_" /* Note that an int is postfixed for the sorting order */ }); /* Amaze UI paging button renderer */ DataTable.ext.renderer.pageButton.amazeui = function(settings, host, idx, buttons, page, pages) { var api = new DataTable.Api(settings); var classes = settings.oClasses; var lang = settings.oLanguage.oPaginate; var btnDisplay, btnClass, counter = 0; var attach = function(container, buttons) { var i, ien, node, button; var clickHandler = function(e) { e.preventDefault(); if (!$(e.currentTarget).hasClass('am-disabled')) { api.page(e.data.action).draw(false); } }; for (i = 0, ien = buttons.length; i < ien; i++) { button = buttons[i]; if ($.isArray(button)) { attach(container, button); } else { btnDisplay = ''; btnClass = ''; switch (button) { case 'ellipsis': btnDisplay = '…'; btnClass = 'am-disabled'; break; case 'first': btnDisplay = lang.sFirst; btnClass = button + (page > 0 ? '' : ' am-disabled'); break; case 'previous': btnDisplay = lang.sPrevious; btnClass = button + (page > 0 ? '' : ' am-disabled'); break; case 'next': btnDisplay = lang.sNext; btnClass = button + (page < pages - 1 ? '' : ' am-disabled'); break; case 'last': btnDisplay = lang.sLast; btnClass = button + (page < pages - 1 ? '' : ' am-disabled'); break; default: btnDisplay = button + 1; btnClass = page === button ? 'am-active' : ''; break; } if (btnDisplay) { node = $('