• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 975
  • Last Modified:

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' );          
    });
0
UniqueData
Asked:
UniqueData
  • 2
  • 2
1 Solution
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
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
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
fyi, the link above was fixed and you will need to click on the first column of the first row for "a tiger nixon"
0
 
UniqueDataAuthor Commented:
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

0
 
UniqueDataAuthor Commented:
Thank you for getting me on the right path :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now