简体   繁体   中英

How to get the Hidden column value from Jquery DataTable 1.10.12

How to get the hidden column value PID from JQUERY data table to pass in URL to another .aspx page Where I can show the detailed description of person & firms in FirmsDeatils.aspx page. Any Help would be great .

<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>

Use the code below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM