如何从Jquery DataTable 1.10.12获取隐藏列值

时间:2016-10-20 11:34:48

标签: javascript jquery datatables

如何从JQUERY数据表中获取隐藏的列值PID以将URL传递到另一个.aspx页面我可以在其中显示person&的详细说明。公司在FirmsDeatils.aspx页面。任何帮助都会很棒。

<script type="text/javascript">
   $(document).ready(function() {
   $.ajax({
  // url: 'FirmDetailService.asmx/GetFirmDetails',
  url: '<%= ResolveUrl("FirmDetailService.asmx/GetFirmDetails")%>',
  method: 'post',
  dataType: 'json',
  success: function(data) {
    $('#example').DataTable({

      //paging:false,
      //ordering : false,
      searchHighlight: true,
      lengthChange: false,
      data: data,
      columns: [{
        'data': 'PID',
        visible: false
      }, {
        'data': 'PersonName',
        'render': function(PersonName) {
          var id = ? ? ? ? ;
     return "<a href= FirmsDeatils.aspx?=" + id + '>' + PersonName + '</a>';
        }

      }, {
        'data': 'CID',
        visible: false
      }, {
        'data': 'CompanyName'
      }, {
        'data': 'City'
      }, {
        'data': 'Country'
      }, ]
    });
    }
    });

   });
  </script>
 </head>

<body>
 <table id="example" class="display" cellspacing="0" width="100%">
 <thead>
  <tr>
    <th>PID</th>
    <th>PersonName</th>
    <th>CID</th>
    <th>CompanyName</th>
    <th>City</th>
    <th>Country</th>
   </tr>
  </thead>
 </table>
</body>

 </html>

2 个答案:

答案 0 :(得分:0)

使用以下代码:

'render': function(data, type, row, meta) {
    var id = row['PID'];
    return '<a href="FirmsDeatils.aspx?=' + id + '">' + data + '</a>';
}

答案 1 :(得分:0)

<script type="text/javascript">
$(document).ready(function () {

    $.ajax({
        // url: 'FirmDetailService.asmx/GetFirmDetails',
        url: '<%= ResolveUrl("FirmDetailService.asmx/GetFirmDetails")%>',
        method: 'post',
        dataType: 'json',
        success: function (data) {
       $('#example').DataTable({

                //paging:false,
                //ordering : false,
                searchHighlight: true,
                lengthChange:false ,
                data: data,
                'columns': [
                         { 'data':'PID', 'visible' : false},

                         {'data' : 'PersonName',
                         'render': function (data, type, row, meta) {
                             var id = row['PID'];
          return '<a href="FirmsDeatils.aspx?=' + id + '">' + data + '</a>';
                         }

                    },
                    { 'data': 'CID', 'visible' :false },
                    { 'data': 'CompanyName'},
                    { 'data': 'City' },
                    { 'data': 'Country' },
                ]

       }

            );

        }
    });
 }
  );
 </script>
<body>
<table id="example" class="display"  cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>PID</th>
            <th>PersonName</th>
            <th>CID</th>
            <th>CompanyName</th>
            <th>City</th>
            <th>Country</th>
        </tr>
    </thead>
</table>
</body>
</html>