简体   繁体   English

Django 中的数据表修改列排序

[英]DataTables in Django modify columns ordering

I write Django app, where I have a base.html template and I defined var table where I declared order by column 0 with 'desc' (look below) So I currently use it some templates, where I extend base.html.我编写了 Django 应用程序,其中我有一个base.html模板,我定义了 var 表,在其中我用 'desc' 声明了第 0 列的顺序(如下所示)所以我目前使用它一些模板,我在其中扩展了 base.ZFC35FDC.30D5FC69D5E8282826 But now I need to sort in new template firstly by the second column, and after that by the first column (like this: "order": [1, 0, 'desc'] ).但是现在我需要先按第二列对新模板进行排序,然后再按第一列排序(例如: "order": [1, 0, 'desc'] )。 I don't know how I modify this variable without a duplicate code.我不知道如何在没有重复代码的情况下修改此变量。 Could somebody help me?有人可以帮我吗?

var table = $('#example').dataTable( {
  "columnDefs": [ {
      "targets": 0,
      "searchable": false,
      "order": [0, 'desc'],
      "ordering": true,
    } ]
} );

In template which extends 'base.html'在扩展'base.html'

<script> 
     //modify order method
</script>

You can set the ordering using .order() then redraw the table:您可以使用.order()设置排序,然后重绘表格:

table.order( [ 1, 'desc' ], [ 0, 'desc' ] ).draw();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM