ypnos-web / cakephp-datatables

CakePHP3 Plugin for DataTables plug-in for jQuery
MIT License
27 stars 24 forks source link

CakePHP 4 #82

Closed umer936 closed 4 months ago

umer936 commented 3 years ago

Using the correct branch for CakePHP 4, I was unable to get the table to display the data for a long time.

I eventually fixed it by changing

<?php
echo $this->DataTables->table('datatable', $options, ['class' => 'table table-striped table-responsive']) ?>

to

<?php
echo $this->DataTables->table('datatable', $options, ['class' => 'table table-striped table-responsive']);
echo $this->Html->scriptBlock($this->DataTables->draw("#datatable", $options)); ?>

I have to use the the 2nd line when I thought it would be added due to the DataTables->table() function Everything works as expected with this change

Could this info be added to the README or some other documentation page?

ypnos commented 3 years ago

That doesn't make much sense to me. If you look at the code: https://github.com/ypnos-web/cakephp-datatables/blob/master/src/View/Helper/DataTablesHelper.php#L76-L78

You can see that your second call is a 1:1 replication of what the table() method does already.

Could you hava a look at the produced HTML output or paste it here?

umer936 commented 3 years ago

I agree. It doesn't make sense to me either as I also went into the table() method before opting for this.

I then went through with debug() inside table() and table() only ever returns <table class="dataTable table table-striped table-responsive" id="datatable"></table>

Changes to my $options array did not make data show up in the table.

Searching for how to make the data show up in the table led me to this section:

e) Now draw the datatable:
echo $this->Html->scriptBlock($this->DataTables->draw("#$id", $options));

in https://github.com/ypnos-web/cakephp-datatables/issues/79#issuecomment-641909787 and decided to try it, which made the tables show up.

Such was the case in 3 different locations on the same site we are using this.

Doing that second line made the table show up with data. Without it, it only returns the table tags. (Everything else being the same, such as the options array)