I Created the Customer Custom Attribute using Upgrade Schema Like This

public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        $sortOrder = 200;
        if (version_compare($context->getVersion(), '2.0.1') < 0) {
            //$this->_addCustomerAttributeGroup($setup, "Spire Attributes");
            $attributes1 = [
                'customer_id'   =>  'Spire Customer ID',
                'customer_name' =>  'Customer Name',
                'currency'      =>  'Currency',
                'present_bal'   =>  'A/R Balance',
                'credit_line'   =>  'Credit Limit $',
                'disc_pct'      =>  'Discount %',
                'dflt_ship_to'  =>  'Default Ship-To Address',
                'term_code'     =>  'Terms Code',
                'user_type'     =>  'Spire User Type',
                'special_handling'  =>  'Special Handling',
                'discount_code'     =>  'Spire Discount Code',
                'customer_number'   =>  'Customer Number',
                'currency_id'       =>  'Currency Id',
                'currency_code'     =>  'Currency Code',
                'currency_description'  =>  'Currency Description',
                'term_description'  => 'Terms Description',
                'notes'  => 'Spire Notes'
            foreach($attributes1 as $attributeCode => $attributeLabel) {
                $this->_addCustomerAttributeTypeText($setup, $attributeCode, $attributeLabel, $sortOrder);
            $attributes2 = [
                'spire_mod_date'     => 'Spire Modified Date',
                'spire_created_date' => 'Spire Created Date',
            foreach($attributes2 as $attributeCode => $attributeLabel) {
                $this->_addCustomerAttributeTypeDate($setup, $attributeCode, $attributeLabel, $sortOrder);

They Edit From Admin Like This

enter image description here

And Using Customer Grid I add That Custom Attribute in customer Grid Like That my custome_listing.xml file is

<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="customer_columns" class="Magento\Customer\Ui\Component\Listing\Columns">
        <column name="customer_id" class="Vwndor\Module\Ui\Component\Listing\Column\SpireCustomerId">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                   <item name="filter" xsi:type="string">select</item>
                    <item name="editor" xsi:type="string">text</item>
                     <item name="sorting" xsi:type="string">asc</item>
                    <item name="sortable" xsi:type="boolean">true</item>
                    <item name="sortOrder" xsi:type="number">1</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="label" xsi:type="string" translate="true">Spire Customer Id</item>


my Data source file is

     * Prepare Data Source
     * @param array $dataSource
     * @return array
   public function prepareDataSource(array $dataSource)
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {

                $customer  = $this->_customerRepository->getById($item["entity_id"]);
                $spire_id = $customer->getCustomAttribute('customer_id');
                if (!is_null($spire_id) && $spire_id->getValue()) {
                    $item['customer_id'] = $spire_id->getValue(); 
        return $dataSource;

the Admin Grid Show Like This

enter image description here

In that shorting not working when i apply sorting they throw exception error like this

LIMIT 20 {"exception":"[object] (Zend_Db_Statement_Exception(code: 42): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customer_id' in 'order clause', query was: SELECT main_table.*, IFNULL(rnt.name, IFNULL(rct.default_name, main_table.billing_region)) AS billing_region FROM customer_grid_flat AS main_table LEFT JOIN directory_country_region AS rct ON rct.region_id=main_table.billing_region_id LEFT JOIN directory_country_region_name AS rnt ON rnt.region_id=main_table.billing_region_id AND rnt.locale='en_US' ORDER BY customer_id ASC LIMIT 20 at /var/www/html/unobstructedview/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:110, PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customer_id' in 'order clause' at /var/www/html/unobstructedview/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:91)"} []

1 Answer 1


Your customer attribute column not added in the "customer_grid_flat" table

  • in witch table i need to add this ??
    – Jay Parmar
    Commented Feb 9, 2021 at 3:23
  • how can i apply this without add column in customer_grid_flat
    – Jay Parmar
    Commented Feb 9, 2021 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.