微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jQuery – datatables,如何获取列ID

如何获取jQuery的datatable插件中的列ID我需要数据库中更新的列ID。

解决方法

fnGetPosition

Get the array indexes of a particular
cell from it’s DOM element. Best used
in combination with fnGetData().

输入参数:

nNode : the node you want to find the
position of. This my be either a ‘TR’
row or a ‘TD’ cell from the table. The
return parameter depends on this
input.

返回参数:

int or array [ int,int,int ] : if
the node is a table row (TR) then the
return value will be an integer with
the index of the row in the aoData
object. If the node is a table cell
(TD) then the return value will be an
array with [ aoData index row,column
index (discounting hidden rows),column
index (including hidden rows) ].

代码示例:

$(document).ready(function() {
    $('#example tbody td').click( function () {
        /* Get the position of the current data from the node */
        var aPos = oTable.fnGetPosition( this );

        /* Get the data array for this row */
        var aData = oTable.fnGetData( aPos[0] );

        /* Update the data array and return the value */
        aData[ aPos[1] ] = 'clicked';
        this.innerHTML = 'clicked';
    } );

    /* Init DataTables */
    oTable = $('#example').dataTable();
} );

datatables.net

原文地址:https://www.jb51.cc/jquery/182508.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐