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

Using with DataTable extensions #4

Open
nordkite opened this issue Aug 13, 2015 · 9 comments
Open

Using with DataTable extensions #4

nordkite opened this issue Aug 13, 2015 · 9 comments

Comments

@nordkite
Copy link

I have a problem with using extension Yadcf for Datatables. The problem is that in plain Javascript I would write $('#example').dataTable().yadcf([....]); . But in Yii2 it is already initialized and I have the error that data table is initialized twice in Yii and then in JS code. Is there any solution to initialize Yadcf in 'clientOptions' => [..]? Thanks in advance.

@fedemotta
Copy link
Owner

It is an official extension of datatables? Could you provide me a link to the extension?

@nordkite
Copy link
Author

http://yadcf-showcase.appspot.com/
It provides different filters for Data tables.

@fedemotta
Copy link
Owner

It is an unofficial extension. I need to make a generic functionality to
allow the use of any type of extension. Let me think about this.

In the meantime, you can use the data tables asset provided in this yii2
extension and add the yadcf extension like any other js file of your view
(using depends to be sure that it is loaded after the datatables js file).
So basically you can achieve anything you want coding in js like it says in
the readme file and in the datatables documentation. In that case the
extension is still useful because it provides the datatables files.

On Thu, Aug 13, 2015 at 11:05 AM, KirillRyzhkov [email protected]
wrote:

http://yadcf-showcase.appspot.com/
It provides different filters for Data tables.


Reply to this email directly or view it on GitHub
#4 (comment)
.

Federico Nicolás Motta

http://about.me/fedemotta http://about.me/fedemotta

[email protected] [email protected]

@nordkite
Copy link
Author

Ok. That I have already done. The problem is that table is initialized twice in Yii then in JS. In Yii view I have <?= DataTables::widget(['id' => 'posts-grid',]); ,which becomes datatables_posts-grid. Next in JS I write
$( document ).ready(function() {
//New datatable API (capital "D")
var myTable = $('#datatables_posts-grid').DataTable();
yadcf.init(myTable, [
{column_number : 0},
{column_number : 1, filter_type: "text", text_data_delimiter: ","},
{column_number : 2, filter_type: "text", text_data_delimiter: ","},
{column_number : 3, filter_type: "text", text_data_delimiter: ","},
],'footer');
});

With that I have an alert box saying that datatable cannot be reinitialized. I click OK I have filter on the table in everything works but problem is that alert box on page load.

@nordkite
Copy link
Author

Found a fix for now. Need to use retrieve: true option in Yii view provided by Datatables to reinitialize a table in Javascript.
https://datatables.net/manual/tech-notes/3
'clientOptions' => [
"retrieve" => true,
],

And all Datatables options must be in Javascript code because retrieve: true will clear all settings in Yii view.

@fedemotta
Copy link
Owner

You can use yii\grid\GridView instead of 'posts-grid',]); ?> if you want to use datatables through js.

Otherwise It will try to generate 2 datatables in the same object. That is why it is fixed with retrieve => true. In both case all options must be in the Javascript object.

@nordkite
Copy link
Author

You said After #2 It is necessary the implementation of a pagination in the php layer to avoid memory limit errors. Does it mean that Datatables pagination needs to be rewritten to work with Yii?

@fedemotta
Copy link
Owner

No. The datatables pagination is working. The problem is about the way
datatables paginates the data. All the records are already in the html. It
won't work with many records.
On Aug 16, 2015 3:03 PM, "KirillRyzhkov" [email protected] wrote:

You said After #2
#2 It is
necessary the implementation of a pagination in the php layer to avoid
memory limit errors.
Does it mean that Datatables pagination needs to be
rewritten to work with Yii?


Reply to this email directly or view it on GitHub
#4 (comment)
.

@nordkite
Copy link
Author

Ok, thanks for explanation

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