【问题标题】:Reorder options of Datatables column visibility button数据表列可见性按钮的重新排序选项
【发布时间】:2022-08-22 16:29:47
【问题描述】:

我正在使用 Datatables 插件来显示一些数据,并进行服务器端处理。默认情况下,列可见性按钮选项的排序顺序与列顺序匹配。 有没有办法按字母顺序重新排序 Datatables 列可见性按钮的选项?

    标签: javascript jquery datatables


    【解决方案1】:

    我能够使用事件处理程序来完成此操作

    $(document).on("mouseup", ".buttons-colvis", function () {
      // I combined a mouseup event with a delay, because the elements appear to be selectable only after they have been displayed. There may be a better way to approach this
      setTimeout(function () {
        // Reorder elements alphabetically, based on text content
        $('.buttons-columnVisibility').sort(function (a, b) {
          if (a.textContent < b.textContent) {
            return -1;
          } else {
            return 1;
          }
        }).appendTo('.dt-buttons .dropdown-menu'); //  re-attach to the dropdown menu
      }, 250);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-02
      • 2023-03-18
      • 2022-01-27
      • 1970-01-01
      • 1970-01-01
      • 2016-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多