Link to home
Start Free TrialLog in
Avatar of UniqueData
UniqueDataFlag for United States of America

asked on

get cell value in dataTable

I am using datatable.net plugin.  i need to get the value of data that is in the dataset but not displayed in the grid (if that matters).  I have tried several things but can't get it to work.


        var tableTools = new $.fn.dataTable.TableTools( table, {
                  sRowSelect: "os",
                  aButtons: [
                  {
                      sExtends: 'select_single',
                      sButtonClass: 'marginLeft',
                      sButtonText: 'View History',
                      editor: editor,
                      fnClick: function () {
                        //window.location.href = 'grid_staffHistory.php';
                        //alert( 'Row index: '+table.row( '.selected' ).index() );
                        alert( 'primary key: '+table.row( '.selected' ).cell('usertable.uuk').data() );
                        //alert( 'Row index: '+ editor.get('usertable.uuk') );
                      }
                  },                  
                  {
                      sExtends: 'select_single',
                      sButtonClass: 'marginLeft',
                      sButtonText: 'Add New Staff',
                      fnClick: function () {
                        window.location.href = 'addUsers.php';
                      }
                  }                      
                  ]
              } );
        $( tableTools.fnContainer() ).insertBefore( '#table_filter' );          
    });
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

If you need to get data you are not placing in the table, you can put it in an attribute like
 <td data-extra="abc123">a Tiger Nixon</td>

Open in new window

I created a datatable example from the zero config for you http://jsbin.com/pacaguyuzi/1/edit?html,js,output

Note the first column on the first row has the data- attribute.
<tr>
                <td data-extra="abc123">a Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>61</td>
                <td>2011/04/25</td>
                <td>$320,800</td>
            </tr>

Open in new window


I used the code below to get it
$(document).ready(function() {
    $('#example').DataTable();
     $('td').click(function(){
       var t=$(this).text();
       var e =$(this).attr('data-extra');
       alert(t);
       alert(e);
     }); 
      
} );

Open in new window

Give the sample a try and let me know if that is what you are trying to do
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of UniqueData

ASKER

your answer let me down the right path.  When I defined the editor I needed to include that field, but as hidden.  Then, one of the lines I had commented out would work.

        editor = new $.fn.dataTable.Editor( {
            serverSide: true,
            ajax: "lib/getdata.php",
            table: "#table",
            idSrc: "usertable.uuk",
            fields: [
              {
                name: "usertable.uuk", 
                visible: "false"
              },
            //rest of visible fields here

Open in new window


then...
        var tableTools = new $.fn.dataTable.TableTools( table, {
                  sRowSelect: "os",
                  aButtons: [
                  {
                      sExtends: 'select_single',
                      sButtonClass: 'marginLeft',
                      sButtonText: 'View History',
                      editor: editor,
                      fnClick: function () {
                        //window.location.href = 'grid_staffHistory.php';
                        alert( 'Row identifier: '+ editor.get('usertable.uuk') );
                      }
                  },  

Open in new window

Thank you for getting me on the right path :)