jQuery - 数据表,如何获取列 id [英] jQuery - datatables, how to get column id
问题描述
如何在 jquery 的数据表插件中获取列 id 我需要列 id 来更新数据库.
How to get a column id in datatable plugin for jquery I need column id for the update in database.
推荐答案
fnGetPosition
获取特定的数组索引来自它的 DOM 元素的单元格.最好用结合 fnGetData().
Get the array indexes of a particular cell from it's DOM element. Best used in combination with fnGetData().
输入参数:
nNode : 要查找的节点的位置.这我要么是'TR'行或表格中的TD"单元格.这返回参数取决于此输入.
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 或数组 [ int, int, int ] : 如果该节点是一个表行(TR)然后返回值将是一个整数aoData 中行的索引目的.如果节点是表格单元格(TD) 那么返回值将是一个带有 [ aoData 索引行、列的数组索引(折扣隐藏行),列索引(包括隐藏行)].
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();
} );
这篇关于jQuery - 数据表,如何获取列 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!