【问题标题】:django_tables2 & excelTableFilter overwrite header chevrondjango_tables2 & excelTableFilter 覆盖标题 chevron
【发布时间】:2019-03-29 00:05:22
【问题描述】:

excelTableFilter:https://www.jqueryscript.net/table/Excel-like-Bootstrap-Table-Sorting-Filtering-Plugin.html

django_tables2:https://github.com/jieter/django-tables2

excelTableFilter 让 HTML 表格像 excel 一样更易于搜索/过滤/排序,django_tables2 让您可以更好地控制表格的呈现方式。

但是 excelTableFilter 中的过滤器按钮在移动设备上非常大,而且几乎没有大小。我的目标是用 excelTableFilter 中的弹出菜单替换 django_tables2 的 a-z, z-a sortng 默认值。

经过 2-3 小时的挖掘,这是我的解决方案:

(我很想得到反馈/不那么老套的解决方案)

【问题讨论】:

    标签: javascript python jquery django django-tables2


    【解决方案1】:

    JS:

    首先我将 excelTableFilter 应用于我的目标表:

    <script>
      $('#workorder_table').excelTableFilter();
    </script>
    

    接下来我删除了所有的图标标签:

    <script>
      $('.glyphicon').removeClass('glyphicon-arrow-down')
      $('.glyphicon').removeClass('dropdown-filter-icon')
      $('.glyphicon').addClass('glyphicon-filter');
    </script>
    

    然后我编写了一个函数来拦截类“click_redirect”的所有点击,并将它们重定向到树中的“向下箭头”类元素

    <script>
      $(document).on('click', '.click_redirect', function(event) {
        event.stopPropagation();
        $(event.target).parent().find('.arrow-down')[0].click();
      });
    </script>
    

    接下来,我将该类应用于我的所有标题,并将它们的排序 url 替换为 #

    <script>
      function update_djheaders(param) {
        param.setAttribute("class", "click_redirect");
        param.setAttribute("href", "#");
      };
    
      $.each($("th.orderable a"), function(i,l) {update_djheaders(l)});
    </script>
    

    CSS:

    最后,我应用下面的 css 来隐藏图标

    <style>
      .arrow-down {
        display:none !important;
      }
    </style>
    

    希望这可以为大家节省一些时间!

    【讨论】:

      猜你喜欢
      • 2018-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      相关资源
      最近更新 更多