Ajax datatable saved into an Array issue - Help would be appreciated

Ajax datatable saved into an Array issue - Help would be appreciated

jcglazierjcglazier Posts: 7Questions: 2Answers: 0
edited February 14 in Free community support

Hi all, I have my Datatable populated through Ajax server side processing & it's working great.
I'm looking to have the data it contains summarised to be used within some GoogleCharts.

In my previous version using an object populated html table I was able to perform the following three commands to give me the data I required.

        dtable.on('search.dt', function() {

                var filterdataarray = ( dtable.rows( { filter : 'applied'} ).data().toArray() )
                var salestagesummary = _.countBy(filterdataarray,'Sales Stage');
                var salesstageobj = Object.entries(salestagesummary);

However, now in my revamped method I'm attempting the same methodology below (as a test), to try & make my Datatables data available within an array.

                   $('#personTable tbody').on( 'click', 'tr', function () {

                       var ids = table.rows().data().toArray();
                        console.log(ids);

I have no issues within my server logs, however my console is giving me the following error message:
table.rows is not a function. (In 'table.rows()', 'table.rows' is undefined)

Any guidance on how to to fix this issue would be greatly appreciated, my current code is below, thank you in advance.

<script>
var table;

jQuery(document).ready(function() {

    table = $('#personTable').dataTable({

            "bPaginate": true,
            "scrollY":        "200px",
            "scrollCollapse": true,
            "pageLength": 50,
            "order": [ 0, 'asc' ],
            "bInfo": true,
            "iDisplayStart":0,
            "bProcessing" : true,
            "bServerSide" : true,
            "sAjaxSource" : "org/mlb/simplewebapp/servlet/JqueryDatatablePluginDemo.java",
    
            "dom": 'C<"clear">lfrtip',
            "language": {
            "infoFiltered": ""
            },
            "dom": 'lBfrtip',
            buttons: [ 'copy', 'excel', 'pdf', 'colvis' ],
          })
              .columnFilter({
                  aoColumns: [ 
                             { type: "text"},
                             { type: "text"},
                             { type: "text"},
                             { type: "text"},
                             { type: "text"},
                             { type: "text"},
                            ],
               }).fnSetFilteringDelay();
            $("#personTable_length").hide();
                   table.fnStandingRedraw();



    
                    } );

           });
                

    </script>

Replies

  • kthorngrenkthorngren Posts: 3,939Questions: 19Answers: 871

    You are using this:
    table = $('#personTable').dataTable({.....})

    This creates a jQuery object not an API instance. Change to this (DataTable with a capital D):
    table = $('#personTable').DataTable({.....})

    table will now contain an API instance. More details in the first FAQ here:
    https://datatables.net/faqs/index#Most-common-FAQs

    Kevin

  • jcglazierjcglazier Posts: 7Questions: 2Answers: 0

    thanks Kevin; is there any other way to do this, other than changing from 'dataTable' to 'Datatable'? This seems to throw up some warnings/break some other things, which would most likely take a while to fix?

  • jcglazierjcglazier Posts: 7Questions: 2Answers: 0

    Ignore - Managed to do through:

    var ids = table._('tr').toArray();
    

    Thanks for highlighting Kevin :)

Sign In or Register to comment.