Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

t[o].cells[n] is undefined #23

Closed
neoacevedo opened this issue May 2, 2017 · 10 comments
Closed

t[o].cells[n] is undefined #23

neoacevedo opened this issue May 2, 2017 · 10 comments

Comments

@neoacevedo
Copy link

Hi, I have downloaded and I am implementing this plugin on a table with dynamic loaded rows from PHP but I am getting this error: t[o].cells[n] is undefined

I have initialized the datatable with $('#my-table').datatable({ pageSize: 10 });

Do I am forgetting something?

@Holt59
Copy link
Owner

Holt59 commented May 2, 2017

How do you load the rows?

@neoacevedo
Copy link
Author

neoacevedo commented May 2, 2017

I load an array of objects. I "render" a view. In this view, I iter this array with a foreach, creating a row on each iteration:
`

      <tr style="color: black;">
	  <td><?= $object->id ?></td>
	  <td>
	      <?php
	      if ($object->user->first_name !== null) {
		  echo $object->user->first_name . " " . $object->user->last_name;
	      } else {
		  echo "Sin Asignar";
	      }
	      ?>
	  </td>
	  <td>
	      <?php
	      echo date("d M Y H:i:s", strtotime($object->date));
	      ?>
	  </td>
	  <td><?= "$object->distance Km" ?></td>
	  <td>
	      <?php
	      setlocale(LC_MONETARY, 'es_CO');
	      if (function_exists("money_format")) {
		  echo money_format("%.0n", $object->total);
	      } else {
		  $fmt = new NumberFormatter('es_CO', NumberFormatter::CURRENCY);
		  echo $fmt->formatCurrency($object->total, "COP");
	      }
	      ?>
	  </td>
      </tr>
      
  `

this last one row is out of the foreach and will show only an info:
<tr style="color: black;"> <td colspan=3"">&nbsp;</td> <td><strong>Total:</strong></td> <td> <?php setlocale(LC_MONETARY, 'es_CO'); if (function_exists("money_format")) { echo money_format("%.0n", $total); } else { $fmt = new NumberFormatter('es_CO', NumberFormatter::CURRENCY); echo $fmt->formatCurrency($total, "COP"); } ?> </td> </tr>

I apologize but the content is not loading all: the line for the foreach is not loaded but looks like: foreach($objects as $object):

I forgot to mention: I am doing it in a WP plugin built by myself.

@Holt59
Copy link
Owner

Holt59 commented May 2, 2017

I thought you were loading data with AJAX, which you are not. Could you use the non-compressed file (without .min) and show the error you get? Could you also show me the HTML table you get before using datatable (with pastebin or a gisthub)?

@neoacevedo
Copy link
Author

neoacevedo commented May 2, 2017

https://pastebin.com/4a2TumV5

TypeError: rows[i].cells[j] is undefined datatable.js:135:17

Table structure validated without errors

All is made with a custom WP Plugin. WP 4.7.4, jQuery 1.12.4

@Holt59
Copy link
Owner

Holt59 commented May 2, 2017

I think the problem is the footer - The plugin is currently not really made to work with non-data rows unfortunately.

Could you try without the footer and see what you get?

@neoacevedo
Copy link
Author

Yes, you are right. I closed the table before the last one row, and this last one was put onto a new table and finally I could see the pagination and the table rows are showed as expected.

Thank you so much :)

@Holt59
Copy link
Owner

Holt59 commented May 2, 2017

The plugin actually recreates the table each time you do operations on it (changing page, filtering, sorting, etc.), so you cannot add extra row in the table.

However, if you wrap the row in a tbody and the footer in a tfooter, everything should work as expected!

@Holt59
Copy link
Owner

Holt59 commented May 2, 2017

Okay, this currently does not work, but this is not expected, so I am going to fix this ASAP so you can have a footer on your table!

@Holt59
Copy link
Owner

Holt59 commented May 2, 2017

@NestorAcevedo This should be fixed with latest commit so you can add a tfooter and it will stay in place when the table is refreshed (tested with your table).

@neoacevedo
Copy link
Author

Ah ok, so if I put a tfooter it should work. I will do. Again, thank you and don't worry, is working. this last one will be a new feature and a great improvement for your plugin that many of us will thank :)

@Holt59 Holt59 closed this as completed Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants