yii2-widget-datatables
yii2-widget-datatables copied to clipboard
Using with DataTable extensions
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.
It is an official extension of datatables? Could you provide me a link to the extension?
http://yadcf-showcase.appspot.com/ It provides different filters for Data tables.
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 https://github.com/fedemotta/yii2-widget-datatables/issues/4#issuecomment-130685248 .
Federico Nicolás Motta
http://about.me/fedemotta http://about.me/fedemotta
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.
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.
You can use yii\grid\GridView instead of = DataTables::widget(['id' => '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.
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?
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 https://github.com/fedemotta/yii2-widget-datatables/issues/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 https://github.com/fedemotta/yii2-widget-datatables/issues/4#issuecomment-131596700 .
Ok, thanks for explanation