如何使用jQuery DataTables捕获所选行中的数据

前端之家收集整理的这篇文章主要介绍了如何使用jQuery DataTables捕获所选行中的数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个datatable设置:
$(document).ready(function() {
    $('#RectifiedCount').dataTable( {
        "bJQueryUI": true,"bProcessing": true,"aLengthMenu": [[10,25,50,-1],[10,"All"]],"bStateSave": true,"sDom": '<"H"if>tr<"F"lTp>',"aoColumns":[
                     {'sname':'count_id','sType':'numeric','bVisible':false},{'sName':'count_type','sType':'string','bVisible':true},{'sName':'count_date','sType':'date',{'sName':'count_count',{'sName':'count_notes','bVisible':true}
                     ],"oTableTools": {
            "sRowSelect": "single","sSwfPath": "media/swf/copy_cvs_xls_pdf.swf","aButtons": [ {sExtends :'select_none','sButtonText':'Clear Selection'}],"fnRowSelected": function(node){
                var s=$(node).children();
                if($(s[0]).text()=='Delivery') return ;
                $('select[name="count_type"]').val($(s[0]).text());
                $('input[name="count_date"]').val($(s[1]).text());
                $('input[name="count_count"]').val($(s[2]).text());
                $('textarea[name="count_notes"]').val($(s[3]).text());
            }
        },'sScrollX':'100%'
    });
});

当我选择一行时,我想将该行的单元格的值复制到与“sName”属性相同的表单字段中.我有两个问题:

>是否有一个TableTools方法来访问所选行中的单元格的值?像node [‘sName_whatever’].值会很好.
>如何获取bVisible = false的单元格的值?

ETA解决方

(留下不重要的东西)

$(document).ready(function() {
    rctable=$('#RectifiedCount').dataTable( {
        "aoColumns":[
                     {'sname':'count_id',"fnRowSelected": function(node){
                aData = rctable.fnGetData(node); //nice array of cell values
                if(aData[0]=='Delivery') return ;
                $('select[name="count_type"]').val(aData[0]);
                $('input[name="count_date"]').val(aData[1]);
                $('input[name="count_count"]').val(aData[2]);
                $('textarea[name="count_notes"]').val(aData[3]);            }
        }
    });
});

解决方法

我做了以下:
oTable = $('#RectifiedCount').dataTable( ....);

 $('#RectifiedCount tbody tr').live('click',function (event) {        
    var aData = oTable.fnGetData(this); // get datarow
    if (null != aData)  // null if we clicked on title row
    {
        //now aData[0] - 1st column(count_id),aData[1] -2nd,etc. 
    }
});
原文链接:https://www.f2er.com/jquery/175696.html

猜你在找的jQuery相关文章