DataTable 在单击时获取隐藏列值 [英] DataTable get hidden column value on click

查看:33
本文介绍了DataTable 在单击时获取隐藏列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 Ajax 创建的数据表.但是,我不希望显示所有字段,因此我在不那么重要的字段上将 bVisible 设置为 false.

I have a datatable that is created with Ajax. However, I do not want all the fields to be displayed and thus I set bVisible to false on the not-so-important field.

$(document).ready(function() {
            $('#example').dataTable( {
                "bProcessing": true,
                "sAjaxSource": "../DataQueries/FetchAllSubjectsForBrowse.asp",
                "aoColumns": [ 
                    /* Subject Name */ null,
                    /* Address */ null,
                    /* LinkedWithCompany */ { "bVisible": false},
                    /* Work Tel */ null
                ]
            } );

但是,我希望能够单击一行以检索所有值,包括隐藏的值.所以我尝试了以下方法:

However, I want to be able to click on a row to retrieve all the values including from the hidden ones. So I tried the below:

$('#example tbody tr').live('click', function () {
             var sTitle;
             var nTds = $('td', this);
             var sSubjectName = $(nTds[0]).text();
             var sSubjectAddress = $(nTds[1]).text();
             var sLinkedWithCompany = $(nTds[2]).text();
             var sWorkTel = $(nTds[3]).text();
});

但是,当我检索 sLinkedWithCompany 的值时,它反而给了我 sWorkTel 的值.

However, when I retrieve the value of sLinkedWithCompany, it instead gives me the value of sWorkTel.

我对如何检索这个隐藏值有点困惑.

I am a little confused on how to retrieve this hidden value.

谢谢

推荐答案

这是一个在单击时获取行数据的示例.

Here is an example of getting row's data on a click.

假设表格的每一行都有删除或任何按钮,如果单击该按钮,将获取所选行的数据并执行所需的操作.

Suppose you have Delete or any button with each row of the table and if you click on the button, get the data of the selected row and perform required operation.

$(document).ready(function(){
    $('#example tbody').on('click', '.delete', function(){
        var row = $(this).closest('tr');
        var data = $('#example').dataTable().fnGetData(row);
        console.log(data);
    }); 
});

这篇关于DataTable 在单击时获取隐藏列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆