Datatables - Unknown Parameter '5' for row 0
Datatables - Unknown Parameter '5' for row 0

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
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
@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:
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:
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.
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
The only suggestion I have is to remove this code that builds the table
thead
:And let Datatables build the header with
columns.title
.Kevin
Your
tbody
has 6 columns, yourthead
has 5 columns. That's going to cause this issue. Did you mean to have 6 throughout or 5?Allan