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

Sortable Column for those non-DataColumn? #1576

Closed
qiansen1386 opened this Issue Dec 19, 2013 · 4 comments

Comments

Projects
None yet
5 participants
@qiansen1386
Copy link
Contributor

qiansen1386 commented Dec 19, 2013

In Yii1 if the column is not specified in DataProvider, there will not be any filter and we could not sort the table based on this column as well.
example. we have a column called Subtotal in Quotation_Item gridview.
it may looks like this

array(
            'header'=>'Subtotal',
            'value'=>'$data->getSubtotal()',
            'footer'=>'Total: '.$model->total,
        ), 

But how about we add some variable like compare and filter
E.g.

array(
            'header'=>'Subtotal',
            'filter'=>'number',
            'compare' => 'number'
            'value'=>'$data->getSubtotal()',
            'footer'=>'Total: '.$model->total,
        ), 

I post it here, so that i think that may be a sweet improvement in Yii2. Feel free to correct me, if i said anything wrong. Or we can implement a similar outcome by make some modification in Model instead of View?

I am apologized for my poor English.

@cebe

This comment has been minimized.

Copy link
Member

cebe commented Dec 19, 2013

to allow sorting and filtering your value has to be calculated in the database. if your model calculates it in afterFind() or similar way you are not able to filter or sort by that field anymore.
You can add values to the select query like this:

$query->select[] = 'SUM(price) AS subtotal';

You also need to declare a property in your AR class to hold the value after find.

Marked this issue as documentation to add description about the topics to the guide.

@qiansen1386

This comment has been minimized.

Copy link
Contributor Author

qiansen1386 commented Dec 20, 2013

So you mean we do that inside Model via a SQL statement. Okay. That will work fine.

But is there any way to allow us make a logic columns on the fly, as long as we can define their relation with the primary key? Sorry, I don't have a clearly use case. I just imagine when we need to combine some data from external resources, And that part may not be done by either making a View or other SQL solution.

Or we can use afterFind() to do so as well? Anyway, It is just a suggestion. Whether is it make sense or not?

@samdark samdark removed this from the 2.0 Beta milestone Mar 7, 2014

@qiangxue qiangxue added this to the 2.0 RC milestone Apr 16, 2014

@qiangxue qiangxue modified the milestones: 2.0 RC, 2.0 GA Sep 5, 2014

@qiangxue qiangxue modified the milestones: 2.0 GA, 2.0.1 Oct 10, 2014

@qiangxue qiangxue modified the milestones: 2.0.1, 2.0.x Oct 20, 2014

@dynasource

This comment has been minimized.

Copy link
Member

dynasource commented Oct 29, 2016

docs are quite clear about this.

@dynasource dynasource closed this Oct 29, 2016

@cebe cebe removed this from the 2.0.x milestone Nov 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.