sql >> Database teknologi >  >> RDS >> Mysql

Brug af kolonnealiasser i feltet Sales Order Grid

lad prøve denne første kode

public function setCollection($collection){
    parent::setCollection($collection);
    $collection->getSelect()->join(
        array('address_shipping' => $collection->getTable("sales/order_address")),
        'main_table.entity_id = address_shipping.parent_id AND address_shipping.address_type = "shipping"',
        array('address_shipping.postcode as shippingpostcode')
    );

    $collection->getSelect()->join(
        array('address_billing' => $collection->getTable("sales/order_address")),
        'main_table.entity_id = address_billing.parent_id AND address_billing.address_type = "billing"',
        array('address_billing.postcode as billingpostcode')
    );
}

Anden _prepareColumns() er her,

protected function _prepareColumns(){
     $this->addColumn('shippingpostcode', array(
        'header' => Mage::helper('sales')->__('Shipping Postcode'),
        'index' => 'shippingpostcode',
        'filter_index' => 'address_shipping.postcode'
     ));

    $this->addColumn('billingpostcode', array(
        'header' => Mage::helper('sales')->__('Billing Postcode'),
        'index' => 'billingpostcode',
        'filter_index' => 'address_billing.postcode'  
    ));

return parent::_prepareColumns();

}

hvis du vil vide mere om 'filter_index' , kommenter ind/ud i denne, og prøv derefter at sortere i dit gitter for postnummerkolonnen. Du vil se et andet resultat. Hvis du fjerner filter_index , fejl ved sortering.



  1. Ekko-forespørgsel før udførelse og uden udførelse i codeigniter Active Record

  2. Skinner 3 - Ivrig lastning med betingelser

  3. Vil du gemme almindelig forespørgsel som kolonne?

  4. JDBC Opret tabel Eksempel Brugserklæring