jQuery – datatables,如何获取列ID

前端之家收集整理的这篇文章主要介绍了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.f2er.com/jquery/182508.html

猜你在找的jQuery相关文章