DataTable get hidden column value on click

后端 未结 4 2197
野趣味
野趣味 2021-01-16 03:02

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.



        
4条回答
  •  心在旅途
    2021-01-16 03:17

    I would recommend something like this:

    var data = [];
    $.ajax({url:"../DataQueries/FetchAllSubjectsForBrowse.asp",success:function(result){
      data=result;
    }});
    var i=0;
     data.forEach(function(d) {d.index=i++;});
    
    $('#example').dataTable( {
                "bProcessing": true,
                "aaData":data, 
                "aoColumns": [ 
                    /*index*/
                    /* Subject Name */ null,
                    /* Address */ null,
                    /* LinkedWithCompany */ { "bVisible": false},
                    /* Work Tel */ null
                ]
            } );
    

    Then in your click handler get the index and then access the record in your original data array

    $('#example tbody tr').live('click', function () {
             var sTitle;
             var nTds = $('td', this);
             var index = $(nTds[0]).text();
             var record = data[i];
    });
    

    This is just a starting point, but I hope you get the idea.

提交回复
热议问题