开发者

jQuery plugin tablesorter jSON: o is undefined

开发者 https://www.devze.com 2023-04-06 06:24 出处:网络
I have a table where I store some data. This data is returned from code.php in a JSON structure\' array.

I have a table where I store some data. This data is returned from code.php in a JSON structure' array.

    $("#errtable").tablesorter(); 
 $.getJSON("./include/code.php",  {key:$('#key').val()}, function(data) { 
     // append the "ajax'd" data to the table body 
  $.each(data, function(key) {
    $("#errtable > tbody").append("<tr><td>"+data[key].errorcode+"</td><td>"+data[key].errordescription+"</td></tr>");
  }); 
    // let the plugin know that we made a update 
    $("#errtable").trigger("update"); 
    // set sorting column and direction, this will sort on the first and third column 
    var sorting = [[2,1],[0,0]]; 
    // sort on the first column 
    $("#errtable").trigger("sorton",[sorting]); 
});

The problem is that Firebug shows an error:

o is undefined [Break On This Error] o.count = s[1];

referring to:

    function updateHeaderSortCount(table, sortList) {
        var c = table.config,
            l = sortList.length;
        for (var i = 0; i < l; i++) {
            var s = sortList[i],
                o = c.headerList[s[0]];
            o.count = s[1];
            o.count++;
        }
    }

does anybody can he开发者_如何学Pythonlp me to fix this ?

Thank you.


With the following code you insert two cells per row, if I am not mistaken:

$("#errtable > tbody").append("<tr><td>"+data[key].errorcode+"</td><td>"+data[key].errordescription+"</td></tr>");

And try two sort the third column, which does not exist:

// set sorting column and direction, this will sort on the first and third column 
var sorting = [[2,1],[0,0]]; 

Sorting the second and first - and not the third - should fix the error in my opinion

0

精彩评论

暂无评论...
验证码 换一张
取 消