普通网友 2013-03-28 15:27
浏览 46

数据表中的未定义对象

Have a datatable and using the drill down row. The top row populate data but the link to drill down to the additional row contains a undefined object and I'm stuck right there.

Any help would be so appreciated. oData.code (undefinded) / oData itself will return everything from the linq query but when I start using the oData.etc... the object becomes undefined. Even in the click event I've tried to access oData and drop it in the second TD row and it to is also undefined.

function fnFormatDetails(oTable, nTr) 
{
    var oData = oTable.fnGetData(nTr);

    var sOut =
        '<div>' +
        '<table>' +
        '<tr><td> '+oData.code+' </td><td>  </td><td> </td><td>  </td><td>  </td><td>  </td><td>  </td></tr>'
        '</table>' +
        '</div>';                           

        return sOut;
} //end fnFormatDetails function


$(document).ready(function () 
{
    var anOpen = [];
    var oTable = $('#VADataTable').dataTable(
    {
        "sDom": 'T<"clear">lfrtip',
        "oTableTools":
        {
            "sSwfPath": "/swf/copy_csv_xls_pdf.swf"
        }, //flash must be enabled
        "iDisplayLength": 5, //defalut amount of rows shown on page                
        "bServerSide": false, //uses sever for filter curently turned off                                                
        "bFilter": false, //makes columns clickable to filter 
        "bProcessing": true,
        "bserverSide":false,
        "bJQueryUI": true, //enables user interface 
        "bSort": true, //sorting for columns                               
        "bScrollInfinite": true, //using this takes away ddl of selection
        "sAjaxSource": "Data/IndustryTable",   //where ajax commands renders results                
        "sScrollY": "200px",
        "sScrollX": "100%",
        "sScrollXInner": "100%",
        "bScrollCollapse": true,
        "fnRowCallback": function (nRow, aData) 
        {
            if (aData[0] == "") 
            {
                $('td:eq(0)', nRow).html("+").addClass('control');
            }
            return nRow;
        }, //ends fnRowCallback

        "aoColumns":
        [
            { "sName": "code", "sTitle": "Code" },
            { "sName": "code" },
            { "sName": "data" },
            { "sName": "data" },
            { "sName": "data" },
            { "sName": "data" },
            { "sName": "data" }
        ]
    });

    $('#VADataTable td.control').live('click', function () 
    {
        var nTr = this.parentNode;
        var i = $.inArray(nTr, anOpen);

        if (i === -1) 
        {
            $('td').attr('+');
            var nDetailsRow = oTable.fnOpen(nTr, fnFormatDetails(oTable, nTr), 'details');
            $('div', nDetailsRow).slideDown();
            anOpen.push(nTr);
        } //end if
        else 
        {
            $('td').attr('-');
            $('div', $(nTr).next()[0]).slideUp(function () 
            {
                oTable.fnClose(nTr);
                anOpen.splice(i, 1);
            }); //ends slideUp
        } //ends else
        $('#new tr').after('<td> '+ typeof(oTable.code) +' </td>');

    }); //ends click event
} //ends live event        
)//ends ready function
  • 写回答

1条回答 默认 最新

  • csdn产品小助手 2014-11-07 12:46
    关注

    I believe that just add the "mData" property in "aoColumns", that is the name of fields of database table, and in "fnRowCallback" you must replace "aData[0]" by "aData['code']" like the next example:

    "fnRowCallback": function (nRow, aData) 
        {
            if (aData['code'] == "") 
            {
                $('td:eq(0)', nRow).html("+").addClass('control');
            }
            return nRow;
        }, //ends fnRowCallback
    
        "aoColumns":
        [
            { "mData" : "code", "sName": "code", "sTitle": "Code" },
            { "mData" : "code", "sName": "code" },
            { "mData" : "data", "sName": "data" },
            { "mData" : "data", "sName": "data" },
            { "mData" : "data", "sName": "data" },
            { "mData" : "data", "sName": "data" },
            { "mData" : "data", "sName": "data" }
        ]
    
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮