【问题标题】:Loading Jsons as Columns Instead of Rows in Datatables?将 Json 加载为列而不是数据表中的行?
【发布时间】:2015-10-29 21:55:25
【问题描述】:

根据我通常使用 Jsons 和 Datatables 收集的信息,datatables 会将每条记录加载为表格的一行数据。

我正在尝试找到一种使用 DataTables 将 json 数据加载为列而不是行的好方法。但是我还没有看到一个很好的方法来完成这个。这是我目前加载行的代码:

$(document).ready(function() {

var table = $('#jsontable').dataTable();  //Initialize the datatable

    $('#load').on('click',function(){
        var user = $(this).attr('id');
        if(user != '') 
        { 
        $.ajax({
            url: 'process.php?method=fetchdata',
            dataType: 'json',
            success: function(s){
            console.log(s);
                    oTable.fnClearTable();
                        for(var i = 0; i < s.length; i++) {
                         table.fnAddData([
                                    s[i][0],
                                    s[i][1],
                                    s[i][2],
                                    s[i][3],
                                    s[i][4]
                                           ]);                                      
                                        } // End For

            },
            error: function(e){
               console.log(e.responseText); 
            }
            });
        }
    });
});

【问题讨论】:

  • 不清楚将json数据加载为列是什么意思?

标签: jquery json datatables


【解决方案1】:

或许你可以试着想一想如何将列转换为行,以及在 App 的哪个点上做。

我建议在 SQL 级别进行。

检查此SQL Server : Columns to Rows 或者这个SQL query to convert columns into rows

如果您想在 JavaScript 中执行此操作,请查看 Swap rows with columns (transposition) of a matrix in javascript

【讨论】:

    猜你喜欢
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    相关资源
    最近更新 更多