I am using CArrayDataProvider with CGridView, sort is working nicely, however, I have a problem on the sorting of the name. Why the sorting name is case sensitive, they display the capital letters first from A-Z then a-z? Can I make it case insensitive?
In Yii 1.1.8, you can override CArrayDataProvider sortData function. I didn’t give it a rigorous workout , but seems to work fine for my application:
class myCArrayDataProvider extends CArrayDataProvider {
public $casei = false;
protected function sortData($directions)
{
if(empty($directions))
return;
$args=array();
$dummy=array();
foreach($directions as $name=>$descending)
{
$column=array();
foreach($this->rawData as $index=>$data)
$column[$index]=is_object($data) ? $data->$name : $data[$name];
$args[]=&$column;
$dummy[]=&$column;
unset($column);
$direction=$descending ? SORT_DESC : SORT_ASC;
$args[]=&$direction;
$dummy[]=&$direction;
unset($direction);
}
if ($this->casei) {
for ($i = 0; $i < count($args); $i++) {
$args[$i] = (is_array($args[$i])) ? array_map('strtolower', $args[$i]) : $args[$i];
}
}
$args[]=&$this->rawData;
call_user_func_array('array_multisort', $args);
}
}
Then when creating your dataProvider:
$dataProvider = new myCArrayDataProvider($proj_result, array(
[rest of your params...]
));
$dataProvider->casei = true;
If you always wanted it case insensitive you could leave out the "casei" param.