Datatables - Unknown Parameter '5' for row 0

Datatables - Unknown Parameter '5' for row 0

egyptmapegyptmap Posts: 2Questions: 1Answers: 0
edited September 2019 in Free community support

I'm running into an issue that is driving me up the wall. I'm using datatables and I have successfully setup all but one table on a page. Here is the script that sets it up on the page:

>             
            > leadRemindersDatatable = $('#leadRemindersDatatable').DataTable({
            >     dom: "<?php echo ($dont_show_new_reminder_btn) ? 'Bfrtip' : "B < 'toolbar' > frtip " ; ?>",
            >     "language": {
            >         "lengthMenu": '_MENU_ ',
            >         "search": '',
            >         "searchPlaceholder": "<?php echo  __('form.search') ; ?>"
            >     },
            >     responsive: true,
            >     processing: true,
            >     serverSide: true,
            >     pageLength: 25,
            >     ordering: false,
            >     "ajax": {
            >         "url": '<?php echo route("datatables_reminders"); ?>',
            >         "type": "POST",
            >         'headers': {
            >             'X-CSRF-TOKEN': '<?php echo  csrf_token() ; ?>'
            >         },
            >         "data": function (d) {
            >             d.remindable_type = "<?php echo $remindable_type; ; ?>";
            >             d.remindable_id = "<?php echo $remindable_id; ; ?>";
            > 
            >         }
            >     }
            > });
            > 

And here is the returned response JSON from the backend:

    {
        "draw": 1,
        "recordsTotal": 1,
        "recordsFiltered": 1,
        "data": [
            [
                "Don't forget this!",
                "2019-09-06",
                " <a  class=\"\" href=\"http:\/\/192.168.1.152\/users\/profile\/1\">Matthew Prythero<\/a>",
                "No",
                "<a class=\"edit_item btn btn-light btn-sm\" data-id=\"1\" href=\"#\"><i class=\"far fa-edit\"><\/i><\/a> <a class=\"delete_item btn btn-danger btn-sm\" href=\"http:\/\/192.168.1.152\/reminders\/remove\/1\"><i class=\"far fa-trash-alt\"><\/i><\/a>"
            ]
        ]
    } 

As you can see, the returned response never goes past the 4th index. But I don't know why it moves on and tries to create a table cell from an unknown 5th index.

This is the base html for my table in html:

        <table class="table table-striped table-bordered" cellspacing="0" width="100%" id="leadRemindersDatatable">
            <thead>
                <tr>
                    <th><?php echo __("form.description");?></th>
                    <th><?php echo __("form.date");?></th>
                    <th><?php echo __("form.remind");?></th>
                    <th><?php echo __("form.is_notified");?></th>
                    <th><?php echo __("form.action");?></th>
                </tr>
            </thead>
        </table>

If anyone can help, I'd be extremely appreciative. Thank you!

Edited by Kevin:  Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

Answers

  • kthorngrenkthorngren Posts: 20,322Questions: 26Answers: 4,774

    It does look like it should work. Any chance you can post a link to your page so we can take a look?

    I would probably start by using the browsers inspect tool to make sure the table is rendered as expected. Maybe there is something in one of the variables used to build the header that is causing the thead to be different than expected. Hard to say without seeing the problem page.

    Kevin

  • egyptmapegyptmap Posts: 2Questions: 1Answers: 0
    edited September 2019

    @kthorngren - At the moment, I can't, just an odd internal mess I had the "fortune" of inheriting.... Let me see if I can work around that problem though.

    For the time being, this is my output thead html:

        <thead>
                <tr role="row">
    <th class="sorting_disabled" rowspan="1" colspan="1">Description</th>
    <th class="sorting_disabled" rowspan="1" colspan="1">Date</th>
    <th class="sorting_disabled" rowspan="1" colspan="1">Remind</th>
    <th class="sorting_disabled" rowspan="1" colspan="1">Is Notified</th>
    <th class="sorting_disabled" rowspan="1" colspan="1">Action</th>
    </tr>
                </thead>
    

    I believe that all looks correct, so I'm stumped... since there's only one record for this particular table at the moment though, here's what the output is in the tbody:

    <tbody>
    <tr role="row" class="odd">
    <td>Don't forget this!</td>
    <td>2019-09-06</td>
    <td> <a class="" href="#">Matthew Prythero</a></td>
    <td>No</td>
    <td><a class="edit_item btn btn-light btn-sm" data-id="1" href="#"><i class="far fa-edit"></i></a> <a class="delete_item btn btn-danger btn-sm" href="#"><i class="far fa-trash-alt"></i></a></td>
    <td></td>
    </tr>
    </tbody>
    

    It just adds that odd last table cell for some oddball reason...

    Thanks for the start though!

    Matt

    EDIT: Edited by Kevin to make the HTML output more readable.

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    Hi @egyptmap ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 20,322Questions: 26Answers: 4,774
    edited September 2019

    The only suggestion I have is to remove this code that builds the table thead:

        <thead>
            <tr>
                <th><?php echo __("form.description");?></th>
                <th><?php echo __("form.date");?></th>
                <th><?php echo __("form.remind");?></th>
                <th><?php echo __("form.is_notified");?></th>
                <th><?php echo __("form.action");?></th>
            </tr>
        </thead>
    

    And let Datatables build the header with columns.title.

    Kevin

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Your tbody has 6 columns, your thead has 5 columns. That's going to cause this issue. Did you mean to have 6 throughout or 5?

    Allan

This discussion has been closed.