Yii Framework Forum: CGridView - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CGridView sorting on user defined column Rate Topic: -----

#1 User is offline   Chintan Shah 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 31-January 12

Posted 03 February 2012 - 08:17 AM

Here is my Query, which is generated by CSqlDataProvider...

( SELECT e.E_NAME AS "E_NAME", e.E_TLID AS "E_TLID", 
(SELECT E_NAME FROM employee WHERE employee.E_ID = e.E_TLID) as TLNAME,
e.E_DEPTID AS "E_DEPTID",
(SELECT D_NAME FROM department WHERE department.D_ID = e.E_DEPTID) as DPTNAME,
l.LS_FROM AS "LS_FROM", l.LS_TO AS "LS_TO", l.LS_STATUS AS "LS_STATUS",
 l.LS_DAYS AS "LS_DAYS", "L" AS "TYPE", l.LS_ID AS "LEAVEID" FROM 
employee e JOIN leave_summary l on e.E_ID = l.LS_EMPID WHERE 1=1 ) UNION 
( SELECT e.E_NAME AS "E_NAME", e.E_TLID AS "E_TLID", 
(SELECT E_NAME FROM employee WHERE employee.E_ID = e.E_TLID) as TLNAME,
e.E_DEPTID AS "E_DEPTID",
(SELECT D_NAME FROM department WHERE department.D_ID = e.E_DEPTID) as DPTNAME,
c.L_DATE AS "LS_FROM", c.L_DATE AS "LS_TO", c.STATUS AS "LS_STATUS", 
"1" AS "LS_DAYS", "C" AS "TYPE", c.C_ID AS "LEAVEID" 
FROM employee e JOIN comp_off c on e.E_ID = c.E_ID WHERE 1=1 ) 
ORDER BY DPTNAME desc LIMIT 10


Sort Array defined in model

$sort->defaultOrder = 'E_NAME';
	$sort->attributes = array(
		'E_NAME'=>array(
		  'asc'=>'E_NAME',
		  'desc'=>'E_NAME desc',
		),
		'TYPE'=>array(
		  'asc'=>'TYPE',
		  'desc'=>'TYPE desc',
		),	
	);


Code @ Gridview...

array(            // display Type
        'name'=>'Type',
	'type'=>'raw',
        'value'=>array($smodel,'getTypeName'),
),


getTypeName Function in Model..

public function getTypeName($data,$row)
{
	if ( trim($data["TYPE"]) == 'L' )
		return 'Leave';
	else if ( trim($data["TYPE"]) == 'C' )
		return 'Comp. Off.';
}


How can I make TYPE column as sortable?
0

#2 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 03 February 2012 - 11:01 AM

try to force the property 'sortable' to true

array(            // display Type
        'name'=>'Type',
        'type'=>'raw',
        'value'=>array($smodel,'getTypeName'),
        'sortable'=>true
),

--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#3 User is offline   Chintan Shah 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 31-January 12

Posted 04 February 2012 - 12:39 AM

Thanks for the reply, but it's not working...
0

#4 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 822
  • Joined: 02-July 10
  • Location:Central Poland

Posted 04 February 2012 - 05:43 AM

Check if this is not related to case (in one place you use "Type", in other "TYPE"). Define your column in grid like this:
array(
        'name'=>'TYPE', //<- TYPE instead of Type
        'type'=>'raw',
        'value'=>array($smodel,'getTypeName'),
),

grid matches sorting definition with column 'name', so this may be the problem.
red
0

#5 User is offline   Chintan Shah 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 31-January 12

Posted 07 February 2012 - 09:47 AM

Great Man !! redguy, U r Awesome!!!
0

#6 User is offline   sprymanish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 07-June 12

Posted 07 February 2013 - 06:18 AM

View Postredguy, on 04 February 2012 - 05:43 AM, said:

Check if this is not related to case (in one place you use "Type", in other "TYPE"). Define your column in grid like this:
array(
        'name'=>'TYPE', //<- TYPE instead of Type
        'type'=>'raw',
        'value'=>array($smodel,'getTypeName'),
),

grid matches sorting definition with column 'name', so this may be the problem.


Can You please define, what is "TYPE" is here?
0

#7 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 822
  • Joined: 02-July 10
  • Location:Central Poland

Posted 07 February 2013 - 11:29 AM

View Postsprymanish, on 07 February 2013 - 06:18 AM, said:

Can You please define, what is "TYPE" is here?

column name
red
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users