简体   繁体   English

带有JS源的DataTable

[英]DataTable with JS Source

I'm trying to generate some data with Sage Sdata using javascript and after that handle that data with datatables plugin but I'm getting error: 我正在尝试使用javascript使用Sage Sdata生成一些数据,然后使用datatables插件处理该数据,但出现错误:

DataTables warning: table id=example - Requested unknown parameter '1' for row 0. For more information about this error, please see http://datatables.net/tn/4 DataTables警告:表id = example-请求的第0行的未知参数“ 1”。有关此错误的更多信息,请参见http://datatables.net/tn/4

if(aNode2)
{
    resultTextData += '[';
    resultTextData += "'" + aNode1.nodeValue + "'";
    resultTextData += ',';
    resultTextData += "'" +  aNode2.nodeValue + "'";
    resultTextData += ',';
    resultTextData += "'" + aNode3.nodeValue + "'";
    resultTextData += ']';
    resultTextData += ',';
}

var dataSet =   resultTextData ;

console.log(dataSet);

$('#example').dataTable({
    "data": dataSet,
    "aoColumns": [
        { "aDataSort": [ 0, 1 ] },
        { "aDataSort": [ 1, 0 ] },
        { "aDataSort": [ 2, 3 ] }
    ]

});

the data option doesn't not accept string inputs. data选项不接受字符串输入。 See https://datatables.net/reference/option/data 参见https://datatables.net/reference/option/data

DataTables support loading from json-encoded string. DataTables支持从json编码的字符串加载。 Here is Example of converting XML result to array. 这是将XML结果转换为数组的示例。

function FormatDataByIolist($data,$IOlist) {
    $returnAray = array();
    $RecordCount = count($data);
    for($i = 0; $i < $RecordCount; $i++) { 
        $tmpSingleRow = array();
        foreach($IOlist as $colName) {
            $columVal = (string)$data[$i]->$colName;
            $tmpSingleRow[$colName] = $columVal;
        }
        array_push($returnAray,$tmpSingleRow);
        unset($tmpSingleRow);
    }
    return $returnAray;
}

After it you need to convert array to json_encoded string that DataTable can understand. 之后,您需要将数组转换为DataTable可以理解的json_encoded字符串。

$formatted = '{ "data": '.json_encode($returnAray).'}';

After writing this in backend you need to add following row in your datatable definition 在后端写完之后,您需要在数据表定义中添加以下行

"ajax": "your.php?action=getJson"

your.php?action=getJson Method should be GET and should return formatted json-string ( as shown ). your.php?action = getJson方法应为GET,并应返回格式化的json-string(如图所示)。

I thnik, this repository will help you to work with SData. 我想,这个存储库将帮助您使用SData。 ( It is model for working with SData ) https://github.com/AramKocharyan/Sage-SData (这是使用SData的模型) https://github.com/AramKocharyan/Sage-SData

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

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