Not Finding the table.row() method

Not Finding the table.row() method

VineethVineeth Posts: 11Questions: 3Answers: 0

hi,

i had downloaded latest version of the datatable. But.But i am unable to find the table.row() it is giving error.I referred the following example.

https://www.datatables.net/examples/api/row_details.html

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    Hi Vineeth, I can assure you that dataTables().row() does work. But without your code snippet, it's impossible to determine where you went wrong. The mostly likely condition is that you have not named your table (id) correctly or you have not given the column the correct className so the jQuery selector can locate it.

  • VineethVineeth Posts: 11Questions: 3Answers: 0
    edited September 2015

    hi glenderson,
    I had referred the below link.
    https://www.datatables.net/examples/api/row_details.html

    I am giving the code implementation below.Please go through it..

                             var table=  $('#datatable').dataTable({
    
                                // Internationalisation. For more info refer to http://datatables.net/manual/i18n
                                "language": {
                                    "aria": {
                                        "sortAscending": ": activate to sort column ascending",
                                        "sortDescending": ": activate to sort column descending"
                                    },
                                    "emptyTable": "No data available in table",
                                    "info": "Showing _START_ to _END_ of _TOTAL_ entries",
                                    "infoEmpty": "No entries found",
                                    "infoFiltered": "(filtered1 from _MAX_ total entries)",
                                    "lengthMenu": "Show _MENU_ entries",
                                    "search": "Search:",
                                    "zeroRecords": "No matching records found"
                                },
                                "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
                                "bRetrive": true,
                                "bDestroy": true,
                                "columns": [
                                {
                                    "className": 'details-control',
                                    "orderable": false,
                                    "data": null,
                                    "defaultContent": ''
                                },
                                {
                                    "orderable": true
                                },
                                {
                                    "orderable": false
                                },
                                {
                                    "orderable": false
                                }],
                                "lengthMenu": [
                                    [5, 15, 20, -1],
                                    [5, 15, 20, "All"] // change per page values here
                                ],
                                // set the initial value
                                "pageLength": 5,
                                "pagingType": "bootstrap_full_number",
                                "language": {
                                    "search": "My search: ",
                                    "lengthMenu": "  _MENU_ records",
                                    "paginate": {
                                        "previous": "Prev",
                                        "next": "Next",
                                        "last": "Last",
                                        "first": "First"
                                    }
                                },
                                "columnDefs": [{  // set default column settings
                                    'orderable': false,
                                    'targets': [0]
                                }, {
                                    "searchable": false,
                                    "targets": [0]
                                }],
                                "order": [
                                    [1, "asc"]
                                ] // set first column as a default sort by asc
                            });
    
     // Add event listener for opening and closing details
                            $('#datatable tbody').on('click', 'td.details-control', function () {
                                debugger;
                                var tr = $(this).closest('tr');
                                var row = table.row(tr);
    
                                if (row.child.isShown()) {
                                    // This row is already open - close it
                                    row.child.hide();
                                    tr.removeClass('shown');
                                }
                                else {
                                    // Open this row
                                    row.child(format(row.data())).show();
                                    tr.addClass('shown');
                                }
                            });
    
     function format(d) {
                  // `d` is the original data object for the row
                  return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
                      '<tr>' +
                          '<td>Full name:</td>' +
                          '<td>' + d.name + '</td>' +
                      '</tr>' +
                      '<tr>' +
                          '<td>Extension number:</td>' +
                          '<td>' + d.extn + '</td>' +
                      '</tr>' +
                      '<tr>' +
                          '<td>Extra info:</td>' +
                          '<td>And any further details here (images etc)...</td>' +
                      '</tr>' +
                  '</table>';
              }
    
    
  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    ....it is giving error.

    What error?

  • VineethVineeth Posts: 11Questions: 3Answers: 0

    TypeError: table.row is not a function

  • allanallan Posts: 61,946Questions: 1Answers: 10,158 Site admin

    Top FAQ :-)

    Use var table= $('#datatable').DataTable({ instead - note the capital D.

    Allan

  • VineethVineeth Posts: 11Questions: 3Answers: 0

    Hi Allan,

    It is solved thank you very much

This discussion has been closed.