2014-04-17 50 views
1

我想按默認的索引順序設置爲升序,目前它顯示隨機。 我的演示代碼是。如何設置默認的kendoui網格索引順序

<?php 
     // For transfer the data from one page to another page 
     $transportData = new Transport(false); 
     // read($url, $data=null, $type='POST', $dataType='', $contentType='', $cache=false) 
     $transport = $transportData->read($this->Html->url(array('controller'=>'ObjectTypes/lists')), $this->ObjectType->indexFields, 'POST', '', 'application/json'); 
     $schemaModel = new SchemaModel('ID', false); 

     // Format to add field: 
     $model = $schemaModel->addSchemaField('Code'); 
     $model = $schemaModel->addSchemaField('Name'); 

     $schema = $schemaModel->createSchema($model); // create schema with data, errors, model, total. 

     $gridDataSource = new GridDataSource($schema, $transport, '', false); //($schema, $transport='', $data='', $inline=true) 
     $dataSource = $gridDataSource->addProperty('pageSize', 20); 
     $dataSource = $gridDataSource->addProperty('serverPaging', true); 
     $dataSource = $gridDataSource->addProperty('serverSorting', true); 


     $name = new \Kendo\UI\GridColumn(); 
     $name->field('Name') 
       ->headerTemplate('<b>Name</b>') 
       ->title('Name'); 



     // Creating Grid with Sort functionality, Pagination, Filter functionality, Column Reorder functionality, Column Resize functionality, Column Group functionality.. 

     $kendoGrid = new KendoGrid('ObjectType', $dataSource, '', false); 
     $grid = $kendoGrid->get(); 
     $grid->addColumn($code, $name, $command); 

     echo $grid->render(); 
    ?> 
</div> 

所以請建議我如何添加屬性到addcolumn來設置順序。

回答

0

你必須在數據源上設置它。不知道,什麼是GridDataSource類,但我建議呼籲:

$gridDataSource->addProperty('sort', '[{"field":"Name","dir":"asc"}]'); 

,或者如果您在addProperty方法json_encoding值:

$gridDataSource->addProperty('sort', array('field' => 'Name', 'dir' => 'asc'));