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

extraColumns and serverSide does not get along well #57

Open
adantart opened this issue Nov 28, 2019 · 2 comments
Open

extraColumns and serverSide does not get along well #57

adantart opened this issue Nov 28, 2019 · 2 comments

Comments

@adantart
Copy link

adantart commented Nov 28, 2019

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 ? ;-)

@adantart
Copy link
Author

Ok, I found some things ...

I have realized I have to add the extraColumns ALSO in the "datatables" action in the Controller. That's ok ... but I don't understand the example you put here: https://github.com/NullRefExcep/yii2-datatables#extra-columns

  1. you put in the widget configuration the extraColumn array (customPrice)
  2. you put in the "datatables" action the same extraColumn array (customPrice)
  3. but you add in the extraColumn attribute of the column configuration a "customField" (why ?)
  4. also you don't put "data" attribute in the column configuration, and that would crash the applyFilters and orderBy methods

How is the model ? Does it have getCustomPrice() and getCustomField() methods ?

@ZAYEC77
Copy link
Contributor

ZAYEC77 commented Nov 29, 2019

Hey @adantart
My example is general, you don't need to put extraColumns to widget and column config at the same time.
If we are using render we can skip the data attribute. We have data argument in a render function that has all the properties of a particular row.
Extra columns -- it's a way to define some additional data properties, that are not defined in the database or don't mention at any data property.
If you don't have a real column, you need to use an extra column instead of using data.

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