nullrefexcep / yii2-datatables Goto Github PK
View Code? Open in Web Editor NEWYii2 Widget for DataTables jQuery plug-in
Home Page: http://www.datatables.net/
License: MIT License
Yii2 Widget for DataTables jQuery plug-in
Home Page: http://www.datatables.net/
License: MIT License
Guys
the pagination always shows the number one and the button next page doesn't work with option 'serverSide' => true.
DataTableAction, line:
$dataProvider->query = $actionQuery->andWhere($originalQuery->where);
empty AND condition is created when original query is empty, and finally it generate SQL error.
I changed it to:
$dataProvider->query = empty($originalQuery->where) ? $actionQuery : $actionQuery->andWhere($originalQuery->where);
Hi, how can I add the three links in the same column, since with linkcolumn it would be a column for each link.
Thks,
Hello @ZAYEC77,
Hello All,
How to get serverSide work with paging?
Trying it with the basic example seems not working.
Got 10 displayed out of 2000+ without any pagination.
Just like in this screenshot.
In advance thanks.
I have extended column configuration like
[
'label' => 'Name',
'value' => function($data) {
return = $data->name
},
],
And serverSide is set to true.
It is work fine at simple column config, but custom column generates datatables error in alert window DataTables warning: table id=w1 - Requested unknown parameter '0' for row 0
Hello,
i got the problem when do the installation due datatables asset in bower repository is not found
Problem 1
- nullref/yii2-datatables v1.0.2 requires bower-asset/datatables ~1.10 -> no matching package found.
- nullref/yii2-datatables v1.0.1 requires bower-asset/datatables ~1.10 -> no matching package found.
- nullref/yii2-datatables 1.0 requires bower-asset/datatables ~1.10 -> no matching package found.
- Installation request for nullref/yii2-datatables ^1.0 -> satisfiable by nullref/yii2-datatables[1.0, v1.0.1, v1.0.2].
After i searching to https://datatables.net/manual/installation#Bower the name of package has been changed to datatables.net not datatables anymore.
Please, add usage examples to README
How can I define the HTML attributes for the column cells ?
I mean, if I want to put data-attributes, or css classes, ...
How can I define, for example, the orderSecuence in the "aoColumns" DataTable ?
In the version you had in packagist, I can set orderable and orderSequence in the columns, now I can't
In this code
return [
'datatables' => [
'class' => 'nullref\datatable\DataTableAction',
'query' => MyModel::find(),
'applyOrder' => function($query, $columns, $order) {
//custom ordering logic
return $query;
},
'applyFilter' => function($query, $columns, $search) {
//custom search logic
return $query;
},
],
];
how the ordering and search logic works ? Any example, I can not figure out how to manage $query, $columns and $oder/$search.
Is there any other documentation or advanced examples ?
Thank you
At the class LinkColumn,
line 39
link.attr("id", link.attr("id") + meta.row);link.attr("href", link.attr("href") + "?" + jQuery.param(q));
My suggestion
var paramPrefix = link.attr("href").indexOf("?") < 0 ? "?" :"&";
link.attr("id", link.attr("id") + meta.row);link.attr("href", link.attr("href") + paramPrefix + jQuery.param(q));
hello,
when i use serverside i get this error message
Exception 'yii\base\InvalidParamException' with message 'Response content must not be an array.'
return [
'datatables' => [
'class' => 'karauia\datatables\DataTableAction',
'query' => Model::find(),
'applyOrder' => function($query, $columns, $order) {
//custom ordering logic
return $query;
},
'applyFilter' => function($query, $columns, $search) {
//custom search logic
return $query;
},
],
] ;
With your release of 1.1.0, I noticed that you are using sClass, however, the official datatable field is className which I have used in 1.0.4.
Here is a reference:
https://datatables.net/reference/option/columns.className
Please advise.
Thanks
As in php7.2 object is restricted word and causing Fatal error: Cannot use 'Object' as class name as it is reserved, hence we need to change for yii2 version 2.0.13.1
class LinkColumn extends \yii\base\Object
to
class LinkColumn extends \yii\base\baseObject
Please check and update, thank you
I want to display relational field
<?= \nullref\datatable\DataTable::widget([
'tableOptions' => [
'class' => 'table',
'style' => 'width: 100%',
],
'data' => $dataProvider->getModels(),
'scrollY' => '200px',
'scrollCollapse' => true,
'paging' => true,
'columns' => [
[
'label' => 'Bill / Invoice No',
'value' => function($data) {
$invoice1 =$model->invoice->invoiceId ;
return $invoice1;
},
],
'bookingId',
'name'
],
]) ?>
how fetch relational field like $model->invoice->invoiceId, current model has relation with Invoice Model
From email:
We use datatable component from your git repository. And there are potential risk during order data. Please add field name validation for order like filtering option.
Order by not work correctly.
Error line: $actionQuery->addOrderBy([$columns[$key]['data'] => $sort]);
After correction: $actionQuery->addOrderBy([$columns[$item['column']]['data'] => $sort]);
After last update class DataTable starts throw exception:
throw new InvalidConfigException(get_class($this) . '::$data must be set.');
I downloaded the newest package, and that was bad. There were already working code for server side by alladas, i dont know how did you managed to that, but upgrading to yours newest version messed up server side response. [Forking and updating to his code now and packaging, as i cannot allow production servers to stop working due to some not tested upgrades]
Hi and thank you for your awesome work!
I recently upgraded to the latest version of your widget and recognized that some column definitions I was using before do not work any longer. In detail: "type", "searchable", "sortable", "width", "visible" and I do not find out how to make it work again.
Please find some code (the commented sections do not work, one defintion as example).
'data' => 'id',
'title' => 'Column Title',
//'type' => 'num',
//'searchable' => false,
//'sortable' => false,
//'visible' => false,
//'width' => '140',
'render' => new JsExpression('
function ( data, type, full, meta ) {
return data
}'
),`
It would be cool to get some tips on how to use these definitions again.
Kind regards
Chris
Hello,
I have multiple tables in one page and my row filtering won't works.
Wth one table, its working.
the error i get in console is:
TypeError: preSearch[column] is undefined jquery.dataTables.js:9072:6
It seems that the variable responsible of columnsDef option control has been defined, but it is not considered while iterating table features and options
class Order extends ActiveRecord
{
public function getCustomer()
{
return $this->hasOne(Customer::className(), ['id' => 'customer_id']);
}
}
Now i want to make a datatable to show customer name with order id, how can i do that?
'columns' => [
'feedback_name',
'created_by',
'assigned_to',
'assignment_activity_status',
'added_date',
[
'class' => 'nullref\datatable\LinkColumn',
'url' => ['intandem/view'],
'queryParams' => ['id'], -------------> Here i have to pass encoded id field value.
'label' => 'View',
],
],
i want to encode id field value in action column . how can i do this . In queryParams i have to pass encoded value of id field. Please let me know the work around.
Hi:
I'm using last version (1.1.0)
I need to do a custom render of a field, using 2 variables of the model, and one function of the model ... how can I do it ?
I've tried with QueryParams but I think this works only with LinkColumn, not with DataTableColumn...
in my view:
[
'class' => 'nullref\datatable\LinkColumn',
'data' => 'name',
'title' => 'x',
'queryParams' => ['name', 'manager.username', 'age'],
'render' => new JsExpression('function render(data, type, row, meta ){
console.log(row);
return row.name + " " + row["manager.username"] + " " + row["age"];
}'),
],
in my model:
public function age() {
return date("Y") - $this->year_birth;
}
I've tried also with getAge() as function name.
There are twi problems; (althought the console.log(row) shows the correct data)
Thank you !
P.D. If i don't use "title" when using "LinkColumn" it returns a javascript error:
jquery.js:3841 jQuery.Deferred exception: Cannot read property 'replace' of null TypeError: Cannot read property 'replace' of null
Many of the DataTables advanced usage needs to refer to Datatable instance as the variable used to create the object.
In your "run" method, instead of using this:
$this->getView()->registerJs('jQuery("#' . $id . '").DataTable(' . Json::encode($this->getParams()) . ');');
you should use this:
$this->getView()->registerJs('var ' . $id . ' = jQuery("#' . $id . '").DataTable(' . Json::encode($this->getParams()) . ');');
So you can use the variable $id in Javascript to refer to the Datatable instance.
Hello,
I am new to yii.
I am trying to use this widget with no success.
My view has this code:
<?= \nullref\datatable\DataTable::widget([ 'columns' => [ 'invoice_discount_report__debtor__name', 'invoices', 'amount', 'amount_paid', 'discount_applied' ], 'serverSide' => true, 'ajax' => '/api/dashboard/getinvoices/', "sAjaxDataProp"=> "datatables" ]) ?>
The js file:
`var myTable = $('#invoicesTbl').DataTable({
retrieve: true,
paging: false,
"language": {
"emptyTable": "There are no invoices for the company",
"bProcessing": true,
"bDestroy": true,
"sAjaxSource": '/api/dashboard/getinvoices',
"bAutoWidth": true,
"aaSorting": [[ 0, "asc" ]],
"aoColumns": [
{ "bSortable": true, "sWidth": "100%" },
],
}
});
yadcf.init(myTable, [
{column_number : 0, filter_type: "text", text_data_delimiter: ","}
],'footer');
});`
getinvoices function:
`$company_id = Generic::COMPANY_ID;
$report_type = isset($this->dataBody['report_type'])?$this->dataBody['report_type']:Generic::AV;
if ($company_id === null)
$this->sendResponse(501,array('error'=>'Invalid company found'));
$this->sendResponse(200, [
'datatables' => [
'class' => 'nullref\datatable\DataTableAction',
'query' => InvoiceDiscountReport::getInvoices($company_id, $report_type)
],
]);`
Json array returned:
{"datatables":{"class":"nullref\\datatable\\DataTableAction","query":[{"invoice_discount_report__debtor__name" :"BRAD PITT","invoices":"1","amount":"2500.75","amount_paid":"1000.00","discount":"150.00"},{"invoice_discount_report__debtor__name" :"SIGAL ZAHAVI","invoices":"1","amount":"1000.00","amount_paid":"500.00","discount":"100.00"}]}}
Yet, the tables says: No matching records found.
What am I doing wrong? Please help, I am trying to solve this for days now.
Thank you very much
So I'm using this column to display delete action link. But there is no action confirmation when I press it. Custom column with actions in GridView does work though. Any ideas how to fix this? My guess is it's something to do with yii js generation, but I'm not very familiar with framework yet.
[
'class' => 'nullref\datatable\LinkColumn',
'url' => ['/product/delete'],
'options' => [
'id' => 'link-delete',
'title' => Yii::t('yii', 'Delete'),
'data-confirm' => Yii::t('yii', 'Are you sure to delete this item?'),
'data-method' => 'post',
],
'queryParams' => ['id'],
'label' => '<span class="fa fa-trash-o"></span>',
],
I came up with the following solution btw:
[
'class' => 'nullref\datatable\LinkColumn',
'url' => ['/product/delete'],
'options' => [
'id' => 'link-delete',
'onclick' => "return confirm('Are you sure to delete this item?');",
],
'queryParams' => ['id'],
'label' => '<span class="fa fa-trash-o"></span>',
],
Hello Guys,
I am looking for an example of custom ordering and filtering logic with a 'serverSide' option enabled?
That will be great to get a sample of a working sample.
@ZAYEC77 Bravo. Seems great.
In advance thanks.
I have saved my data as array in the datatable how do i go about rendering my datatable
Hi!
Amazing package ;-)
I've tried to activate the serverSide but the datatables action ajax call gives me an error:
Unknown column 'columnNameSpecial' in 'order clause' The SQL being executed was: SELECT * FROM client
ORDER BY columnNameSpecial
LIMIT 10"
being "columnNameSpecial" one of the "extraColumns" I have declared in the widget.
When you use extraColumns to put enhanced information, you need to put the name of the model function in the "data" attribute of each column. I mean, for example:
'columns' => [
[
'data' => 'columnNameSpecial',
'title' => 'Name',
'render' => new JsExpression('function render(data, type, row, meta ){
return row.columnNameSpecial;
}'),
],
....
having in the model for example:
function getColumnNameSpecial() {
return $this->name . " " . $this->lastname;
}
But in the other hand, the applyOrder and applyFilter of 'datatables' array in actions() needs the $column["data"] to be a REAL attribute of the model, because it will construct with that name, the applyFilters and orderBy of the ActiveRecord. That's the reason I have the "sql error" of the beginning.
Any ideas ? ;-)
Pagination not working
Hi:
I'd like to add some attributes to each column's cells ... I think I have here what you'd need (it's tested and working):
In DatatableColumn.php add another public variable:
public $htmlOptions;
In Datatable.php , at the end of method run():
if (isSet($this->_options['htmlOptions'])) {
$js = "";
foreach ($this->_options['htmlOptions'] as $key => $data) {
$column = $key + 1;
$attrs = "";
foreach ($data as $attribute => $value) {
$attrs .= ".attr('".$attribute."', '".$value."')";
}
$js.= "jQuery('#".$id." tbody tr td:nth-child(".$column.")').each(function() { $(this)".$attrs."; });";
}
$this->getView()->registerJs(
<<<JS
{
$('#${id}')
.on( 'init.dt', function () {
$js
});
}
JS
);
}
So then you can for example add htmlOptions in the columns definition:
'columns' => [
[
'data' => 'id',
'title' => 'Id',
'htmlOptions' => [
'class' => 'otherClass'
]
],
[
'data' => 'email',
'title' => 'Email',
'htmlOptions' => [
'class' => 'myClass',
'data-anything' => 'something'
]
],
...
This will generate this:
$('#my_datatable').on( 'init.dt', function () {
jQuery('#my_datatable tbody tr td:nth-child(1)').each(function() { $(this).attr('class', 'otherClass'); });
jQuery('#main_datatable tbody tr td:nth-child(7)').each(function() { $(this).attr('class', 'myClass').attr('data-anything', 'something'); });
});
Setting unknown property: nullref\datatable\DataTableColumn::name
'columns' => [
'consumer',
[
'data' => 'branchName',
'title' => "Branch Name",
'name' => 'branchId'
],
]
Can you help with this? Currently on this version v1.1.0.
how do i apply formatter for a spesific collumn? in example I want to format date or number from the retrieved data
thanks for response
Which option has used to retrieve models relations to datatable?
How this:
Post hasOne Author
$model = Post::find()->all();
$model->author->getFullName();
How do it using this widget to datatables?
Hallo Friend,
thank you for your extension.
i have a custom filter for datatable but i don't know to send parameter in your action. so how i can send my parameter in ajax server side datatable?
please help me..
Hi @ZAYEC77 , thanks for your awesome plugin, it helps a lot.
We are using server-side mode, anything works like a charm excepts the filter.
We set the withColumnFilter=>true but no filter was rendered, and we have just debugged the code, and noticed something strange.
Please see https://github.com/NullRefExcep/yii2-datatables/blob/master/src/DataTable.php#L206
L206 - L216 not executed because no tr/th is rendered in the thead while L203 is executing (as Chrome debugging).
Version of Chrome : 76.0.3809.100
Version of Firefox : 67.0.4 (Same thing like chrome)
We have tried to register table.on('init.dt', func) and table.on('draw.dt', func) events to the datatable and copy/move L203 - L229 to the callback func, now the filter input box are rendered but still work not properly. After input something to filter, ajax request had sent but the response just not filtered, because the parameters inputted was not sent with the request.
That's what we found so far, hope it will be useful to you.
composer require nullref/yii2-datatables gives the following errors:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- nullref/yii2-datatables v1.0.4 requires bower-asset/datatables ~1.10.15 -> no matching package found.
- nullref/yii2-datatables v1.0.3 requires bower-asset/datatables.net ~1.10 -> no matching package found.
- nullref/yii2-datatables v1.0.2 requires bower-asset/datatables ~1.10 -> no matching package found.
- nullref/yii2-datatables v1.0.1 requires bower-asset/datatables ~1.10 -> no matching package found.
- nullref/yii2-datatables 1.0 requires bower-asset/datatables ~1.10 -> no matching package found.
- Installation request for nullref/yii2-datatables ^1.0 -> satisfiable by nullref/yii2-datatables[1.0, v1.0.1, v1.0.2, v1.0.3, v1.0.4]
The datatables package name has been changed on bower. Probably that is causing the issue
Hi!
Amazing package ;)
I've tried to activate the serverSide but i don't know custom value in column widget when i use code
[
'data' => function ($model){
return date_formate(date_created($model->time_created,"Y-m-d"));
},
'title' => \Yii::t('app', 'date'),
'filter' => ['true' => 'Yes', 'false' => 'No'],
],
that not working, so how to use that if i want to custom like that?
Thank you
Hello budy, I'm working with DataTables in a Yii2 Advanced Application, and I was wondering If I could integrate TableTools Extension with your plug-in. Do you know how to do it? If there is another way to do data export (PDF, CSV, ...) I will be grateful if you give me an example.
Here is the extension doc. https://www.datatables.net/extensions/tabletools/
I'm looking forward to hearing from you!
Now bower-asset/datatables.net
links to https://github.com/DataTables/Dist-DataTables , not to https://github.com/DataTables/DataTables
Hi ZAYEC77,
Congratulations for this great extension.
I need your help, to get cell value after have selected a datatable row. How could i identify a cell to get this value later.
Thanks for all,
Alexandre
Hi:
when using 'title' attribute in LinkColumn (to customize the name of the column)
'class' => 'nullref\datatable\LinkColumn',
'render' => new JsExpression('function render(data, type, row, meta ){
return "<a href=\"/custom/url/"+row["id"]+"\">View</a>"
}'),
'title' => 'My title'
shows this error:
Unknown Property โ yii\base\UnknownPropertyException
Setting unknown property: nullref\datatable\LinkColumn::title
Hi guys,
Thanks for the extension you created. I have just installed it but cannot use it properly.
I have copied following part of code into my index.php file where I generate table with use of GridView widget but your code generates just
<table id="w0"></table>
without any data in it. Could you please help me?
<?= \nullref\datatable\DataTable::widget([
'data' => $dataProvider->getModels(),
'columns' => [
'id',
'name',
'email'
],
]) ?>
Hi Guys
Just style type that works is the STYLING_DEFAULT.
When i try use another, the layout shows broken.
Here how i tryed input the configuration at config.php
'assetManager' => [
'bundles' => [
'nullref\datatable\DataTableAsset' => [
'styling' => \nullref\datatable\DataTableAsset::STYLING_BOOTSTRAP,
]
],
],
As in subject
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.