Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8035391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:17:39+00:00 2026-06-05T02:17:39+00:00

In my Vacation model Vac I have this function public function getVacCount(){ this function

  • 0

In my Vacation model Vac I have this function

public function getVacCount(){

this function returns how many days there are in one vacation.

and I want to add a custom column to the cgridview like this:

   <?php
    $this->widget('zii.widgets.grid.CGridView', array(
            ...
            array(
                'name' => 'count',
                'value' => '$data->getVacPeriod()'
            ),
            ...
        ),
    ));
    ?>

it works fine.
but I don’t know how can I sort upon this custom attribute.
I tried to use CSort but it does not work. any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:17:40+00:00Added an answer on June 5, 2026 at 2:17 am

    To use CSort for sorting, you’ll need to convert your vacation function into a SQL query and then stash the results in a public variable in your model.

    CSort only works with SQL statements/functions, as underneath it’s using ORDER BY to do all the sorting.

    More info (and demo code) available here

    Here’s a sample of how I’m doing it on a site of mine:

    $criteria->select = array(
            "*",
            new CDbExpression("IF(survey.RequestDate, survey.RequestDate, SurveyCompleteDate) AS SurveyDate")
        );
    

    This then allows me to do this type of filter:

    return new CActiveDataProvider($this, array(
        'criteria' => $criteria,
        'sort'=>array(
            'attributes'=>array(
                'SurveyDate' => array(
                    'asc' => 'SurveyDate',
                    'desc' => 'SurveyDate DESC',
                ),
                '*',
            ),
        ),
    );
    

    Note: you’ll also need a public variable defined in your model to hold the results of the CDbExpression that you’re doing. Mine is called SurveyDate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a student and I have a lot of free time on this vacation
Consider, if you will, the following tables: Vacation Model http://imagetiger.org/images/vacatilrl.png This may seem like
I have 2 tables (entity) a person entity and a vacation entity. One person
I have a Drupal view that displays vacation leaves for a particular employee. I
I'm trying to make the domain model of a management system. I have the
We have developed a vacation rental application in ASP.NET with SQL server as DB.
I have a question about HTTPService and the data it returns. Well lets consider
Unless Mr.Wizard is on vacation, it is pretty difficult to beat this phenomenon which
I have the following domain class in my grails project: class Vacation { Date
I have telerik controls on my page. I am making a vacation calendar using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.