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

  • Home
  • SEARCH
  • 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 8526913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:24:26+00:00 2026-06-11T08:24:26+00:00

On my Admin side customer grid, i have a situacion, some times and some

  • 0

On my Admin side customer grid, i have a situacion, some times and some customers on column name i need First Name + Last Name, it’s already done by magento core, but some customer i need just to print First name. Take a look on my Grid.php, i need take off last name from ‘name’ catenation, but when i remove from collection my column sort stop work.

<?php

class Mage_Adminhtml_Block_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid
{

public function __construct()
{
    parent::__construct();
    $this->setId('customerGrid');
    $this->setUseAjax(true);
    $this->setDefaultSort('entity_id');
    $this->setSaveParametersInSession(true);
}

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel('customer/customer_collection')
        ->addNameToSelect()
        ->addAttributeToSelect('email')
        ->addAttributeToSelect('created_at')
        ->addAttributeToSelect('group_id')
        ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
        ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
        ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
        ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
        ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');

    /*foreach($collection as $customer){
        preg_match("/[A-z| ]*//*", $customer->getName(), $name);
        $customer->setName($name[0]);
        unset($name);
    }*/

    $this->setCollection($collection);

    return parent::_prepareCollection();
}

protected function _prepareColumns()
{
    $this->addColumn('entity_id', array(
        'header'    => Mage::helper('customer')->__('ID'),
        'width'     => '50px',
        'index'     => 'entity_id',
        'type'  => 'number',
    ));

    /*
    $this->addColumn('firstname', array(
        'header'    => Mage::helper('customer')->__('First Name'),
        'index'     => 'firstname'
    ));
    $this->addColumn('lastname', array(
        'header'    => Mage::helper('customer')->__('Last Name'),
        'index'     => 'lastname'
    ));
    */

    $this->addColumn('name', array(
        'header'    => Mage::helper('customer')->__('Name'),
        'sortable'  => true,
        'index'     => 'name'
    ));

    $this->addColumn('email', array(
        'header'    => Mage::helper('customer')->__('Email'),
        'width'     => '150',
        'index'     => 'email'
    ));

    $groups = Mage::getResourceModel('customer/group_collection')
        ->addFieldToFilter('customer_group_id', array('gt'=> 0))
        ->load()
        ->toOptionHash();

    $this->addColumn('group', array(
        'header'    =>  Mage::helper('customer')->__('Group'),
        'width'     =>  '100',
        'index'     =>  'group_id',
        'type'      =>  'options',
        'options'   =>  $groups,
    ));

    $this->addColumn('Telephone', array(
        'header'    => Mage::helper('customer')->__('Telephone'),
        'width'     => '100',
        'index'     => 'billing_telephone'
    ));

    $this->addColumn('billing_postcode', array(
        'header'    => Mage::helper('customer')->__('ZIP'),
        'width'     => '90',
        'index'     => 'billing_postcode',
    ));

    $this->addColumn('billing_country_id', array(
        'header'    => Mage::helper('customer')->__('Country'),
        'width'     => '100',
        'type'      => 'country',
        'index'     => 'billing_country_id',
    ));

    $this->addColumn('billing_region', array(
        'header'    => Mage::helper('customer')->__('State/Province'),
        'width'     => '100',
        'index'     => 'billing_region',
    ));

    $this->addColumn('customer_since', array(
        'header'    => Mage::helper('customer')->__('Customer Since'),
        'type'      => 'datetime',
        'align'     => 'center',
        'index'     => 'created_at',
        'gmtoffset' => true
    ));

    if (!Mage::app()->isSingleStoreMode()) {
        $this->addColumn('website_id', array(
            'header'    => Mage::helper('customer')->__('Website'),
            'align'     => 'center',
            'width'     => '80px',
            'type'      => 'options',
            'options'   => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
            'index'     => 'website_id',
        ));
    }

    $this->addColumn('action',
        array(
            'header'    =>  Mage::helper('customer')->__('Action'),
            'width'     => '100',
            'type'      => 'action',
            'getter'    => 'getId',
            'actions'   => array(
                array(
                    'caption'   => Mage::helper('customer')->__('Edit'),
                    'url'       => array('base'=> '*/*/edit'),
                    'field'     => 'id'
                )
            ),
            'filter'    => false,
            'sortable'  => false,
            'index'     => 'stores',
            'is_system' => true,
    ));

    $this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
    $this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
    return parent::_prepareColumns();
}

protected function _prepareMassaction()
{
    $this->setMassactionIdField('entity_id');
    $this->getMassactionBlock()->setFormFieldName('customer');

    $this->getMassactionBlock()->addItem('delete', array(
         'label'    => Mage::helper('customer')->__('Delete'),
         'url'      => $this->getUrl('*/*/massDelete'),
         'confirm'  => Mage::helper('customer')->__('Are you sure?')
    ));

    $this->getMassactionBlock()->addItem('newsletter_subscribe', array(
         'label'    => Mage::helper('customer')->__('Subscribe to Newsletter'),
         'url'      => $this->getUrl('*/*/massSubscribe')
    ));

    $this->getMassactionBlock()->addItem('newsletter_unsubscribe', array(
         'label'    => Mage::helper('customer')->__('Unsubscribe from Newsletter'),
         'url'      => $this->getUrl('*/*/massUnsubscribe')
    ));

    $groups = $this->helper('customer')->getGroups()->toOptionArray();

    array_unshift($groups, array('label'=> '', 'value'=> ''));
    $this->getMassactionBlock()->addItem('assign_group', array(
         'label'        => Mage::helper('customer')->__('Assign a Customer Group'),
         'url'          => $this->getUrl('*/*/massAssignGroup'),
         'additional'   => array(
            'visibility'    => array(
                 'name'     => 'group',
                 'type'     => 'select',
                 'class'    => 'required-entry',
                 'label'    => Mage::helper('customer')->__('Group'),
                 'values'   => $groups
             )
        )
    ));

    return $this;
}

public function getGridUrl()
{
    return $this->getUrl('*/*/grid', array('_current'=> true));
}

public function getRowUrl($row)
{
    return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
}

}

Its wrong way i know, but have to get just first name and don’t have other way.
But now this make my sort on columns from grid stop work. I need sort working.
If i remove this 3 lines from my _prepareCollection(), it’s work fine but i need it too and with it don’t work my sort. I’m crazy with this someone can help???

Ty in advise.

  • 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-11T08:24:27+00:00Added an answer on June 11, 2026 at 8:24 am

    You’re best bet would be to load the firstname attribute on the collection and add that as an independent column. Adding column to customer grid in Magento – Data not populating will give you a good start. You should just need to add in ->addAttributeToSelect('firstname') and then add the column in the prepareColumns function…

    $this->addColumn('firstname', array(
        'header'    => Mage::helper('customer')->__('First Name'),
        'index'     => 'firstname'
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added two pages through admin side(About us, privacy policy) How can i
I have a strange need, a customer asked me to implement a webapp to
i have made a huge website(front & admin side) in Zend Framework now i
I have created a Sample Module (Admin Side) in Magento.. I managed To created
I'm working on a project and made a grid on admin side in which
Imagine that I have a store. I have an admin side to the store
I have a database where, on the admin side, the admin enters football players
How to construct a GQL query using server side admin datastore viewer, a one
I have an admin model with a few inline models included with it (see
I have to admin there is slight difference between the columns from both tables.

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.