Quantcast
Channel:
Viewing all articles
Browse latest Browse all 4235

Sorting one Model only in ModelAdmin

$
0
0

Hi,

I've set up a ModelAdmin to manage multiple models. Only one of these requires drag-and-drop sorting.

When I add add sorting capability to the ModelAdmin, it complains because the non sorted Model doesn't have a SortOrder field. How can I specify that GridFieldSortableRows is added only to the Model which is to be sorted?

My code is:

class DAdmin extends ModelAdmin {

   public static $managed_models = array(
      'PCategory',
      'AItem'
   );

   static $url_segment = 'd-admin';
   static $menu_title = 'dAdmin';

   public function getEditForm($id = null, $fields = null) {
      $form = parent::getEditForm($id, $fields);
      $cName = $this->sanitiseClassName($this->modelClass);
      $gridField = $form->Fields()->fieldByName($cName);
      $gridField->getConfig()->addComponent(new GridFieldSortableRows('SortOrder'));
       return $form;
   }
}

Thanks.
VWD.


Posted to: Sorting one Model only in ModelAdmin | Show Thread | Post Reply


Viewing all articles
Browse latest Browse all 4235

Trending Articles