我想按默认设置索引顺序设置为升序,目前显示为随机。 我的演示代码是。
<?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 :(得分:0)
您必须在数据源上进行设置。不确定,GridDataSource
类是什么,但我建议调用:
$gridDataSource->addProperty('sort', '[{"field":"Name","dir":"asc"}]');
或者如果您使用addProperty
方法中的json_encoding值:
$gridDataSource->addProperty('sort', array('field' => 'Name', 'dir' => 'asc'));