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

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

问题描述

我有一个使用Ajax创建的datatable。但是,我不希望显示所有的字段,因此我在不太重要的字段上设置为false。

  $(document).ready(function(){
$('#example')。dataTable({
bProcessing:true,
sAjaxSource:../数据查询/ FetchAllSubjectsForBrowse.asp,
aoColumns:[
/ *主题名称* / null,
/ *地址* / null,
/ * LinkedWithCompany * / { bvisible:false},
/ *工作电话* / null
]
});

然而,我想要能够点击一行来检索所有的值,包括从隐藏的值,所以我尝试了以下:

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

但是,当我检索sLinkedWithCompany的值时,它代替给我sWorkTel的值。 p>

我有点困惑如何检索这个隐藏的值。



谢谢

解决方案

这是一个点击获取行的数据的例子。



假设你有删除或表中每一行的任何按钮,如果您点击按钮,获取所选行的数据并执行所需的操作。



<$ p $ ('click','.delete',function(){
$('#example tbody')。 b var row = $(this).closest('tr');
var data = $('#example')。dataTable()。fnGetData(row);
console.log ;
});
});


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();
});

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.

Thanks

解决方案

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天全站免登陆