简体   繁体   English

DataTable Column Reorder 将数据映射到错误的列中

[英]DataTable Column Reorder maps data in wrong columns

I have made following JSBIn in which you can see the code.我制作了以下 JSBIn,您可以在其中看到代码。 Due to CORS policy the ajax url I used is not working but it generates following output in which you can see see data is mapped in wrong columns. Due to CORS policy the ajax url I used is not working but it generates following output in which you can see see data is mapped in wrong columns. Please let me know using same data object column names which I have used how to fix this?请让我知道使用我使用的相同数据 object 列名如何解决这个问题?

数据

https://jsbin.com/ciheragayi/1/edit?html,css,js,output https://jsbin.com/ciheragayi/1/edit?html,css,js,Z78E6221F6339FCE1D

$(document).ready(function() {
    $('#example').DataTable( {
        "ajax": "https://a.uguu.se/8MdQchH6NKHJ_CYF.txt",
      "processing": true,

        "serverSide": true,
        colReorder: true,

        "columns": [
            { "data": "0" },
            { "data": "1" },
            { "data": "2" },
            { "data": "3" },
            { "data": "4" },
            { "data": "5" }
        ],
      colReorder: {
            order: [ 3,5,2,4,1,0 ]
        },
    } );
} );

Be careful in using使用时要小心

colReorder: {
    order: [ 3,5,2,4,1,0]
}

The order would be DATE-ID- SALARY-COUNTRY-POSITION-NAME 3 represents "3" in this JSON Object and so on and so forth订单将是 DATE-ID-SALARY-COUNTRY-POSITION-NAME 3 在此 JSON Object 中代表“3”,依此类推

 {
      "0": "Tiger Nixon",
      "1": "System Architect",
      "2": "$320,800",
      "3": "2011/04/25",
      "4": "Edinburgh",
      "5": "5421"
    }

It's either you adjust the header or you adjust the colReorder or your columns, use this configuration for columns adjustments要么调整 header,要么调整 colReorder 或列,使用此配置进行列调整

        "columns": [
            { "data": "0" },
            { "data": "1" },
            { "data": "4" },
            { "data": "5" },
            { "data": "3" },
            { "data": "2" }
        ]

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

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