Apply jquery on tr

Apply jquery on tr

susersuser Posts: 68Questions: 18Answers: 0
edited July 2016 in Free community support

I try this .

<script type="text/javascript">
      $(document).ready(function () {
          var table = $('#example').DataTable();

          $('#grid tbody').on('click', 'tr', function () {
              $(this).toggleClass('selected');
          });

          $('#button').click(function () {
              alert(table.rows('.selected').data().length + ' row(s) selected');
          });
      });
</script>
<table id="grid" class="display">
   <tr>
   <th>
   Name
   </th>
   <th>
   ID
   </th>
   </tr>
   <tbody>
   <tr>
  <td>
  ABC
  </td>
   <td>
   def
   </td>
   </tr>
   </tbody>
   </table>

also i add links

<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"/>

but table not display like this
-https://datatables.net/examples/api/select_row.html

any help

Answers

  • F12MagicF12Magic Posts: 109Questions: 0Answers: 28

    You are using a stylesheet link and provide a javascript to it.
    Better use:
    <script type="text/javascript" src="path/to/jquery.dataTables.min.js"></script>

  • susersuser Posts: 68Questions: 18Answers: 0

    but i already have static webmethod which return data so why i use this datatables?

  • susersuser Posts: 68Questions: 18Answers: 0
    edited July 2016

    i already add this link

  • F12MagicF12Magic Posts: 109Questions: 0Answers: 28

    If you have loaded the plugin files in the correct way, then the only problem I see from your code is that your table doesn't have a thead tag. Correct that first, like the example below, please.

    <table id="grid" class="display">
    <thead>
        <tr>
           <th>Name</th>
           <th>ID</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>ABC</td>
            <td>def</td>
        </tr>
    </tbody>
    </table>
    
This discussion has been closed.