Magento Grille ->addColumn la longueur de la chaîne
-
12-12-2019 - |
Question
Je suis en train d'afficher le Client initiales à la place des noms et prénoms dans le Client de la Grille.c'est à dire.Au lieu de "M. Jean-Moyen-Smith," je voudrais "M. J M Smith"
Quelqu'un peut-il me diriger dans la bonne direction pour changer cela:
$this->addColumn('firstname', array(
'header' => Mage::helper('customer')->__('First Name'),
'index' => 'firstname',
));
Pour obtenir juste le premier caractère de firstname
Merci :-)
La solution
Vous pouvez utiliser votre propre rendu pour cela.Voir l'exemple:
$this->addColumn('firstname', array(
'header' => Mage::helper('customer')->__('First Name'),
'renderer' => 'amexample/adminhtml_customer_grid_renderer_name',
....
));
La classe de rendu:
class Amasty_Example_Block_Adminhtml_Customer_Grid_Renderer_Name extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
return substr($row->getFirstname(), 0, 1);
}
}
Vous pouvez trouver des rendriers par défaut ici:
app \ code \ core \ mage \ adminhtml \ block \ widget \ grille \ colonne \ rendu
Autres conseils
Étape 1: Vous devez remplacer le fichier dans le dossier local ou tout simplement copier app\code\core\Mage\Adminhtml\Block\Customer\Grid.php
pour app\code\local\Mage\Adminhtml\Block\Customer\Grid.php
Étape 2: Remplacer le code ci-dessous avec
$this->addColumn('name', array(
'header' => Mage::helper('customer')->__('Name'),
'index' => 'name'
));
Remplacer par
$this->addColumn('namewithprifx', array(
'header' => Mage::helper('customer')->__('First Name'),
'index' => 'firstname',
'type' => 'text',
'width' => '250px',
'sortable' =>false,
'filter' => false,
'renderer' => 'NameSpace_Customergrid_Block_Adminhtml_Renderer_Namewithprifx',
));
Étape 3: Créer un fichier dans NameSpace\Customergrid\Block\Adminhtml\Renderer\Namewithprifx.php
Étape 4: Copie de code ci-dessous.
<?php
class NameSpace_Customergrid_Block_Adminhtml_Renderer_Namewithprifx extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
//$getData = $row->getData();
$str=$row->getData('prefix'). " ". $row->getData('fname'). " ". $row->getData('lname');
return $str;
}
}
Étape 5: Actualisation du cache et de vérifier les données.