我使用jqGrid 4.4.0和jQuery 1.7.2(我也尝试过最新版本的jqgrid和jquery)。我像这样使用treegrid:
jQuery('#projects_grid').jqGrid({
treeGrid: true,
treeGridModel: 'adjacency',
ExpandColumn: 'ProjectName',
url: 'jqGridTestHandler.ashx?q=tree',
treedatatype: 'xml',
mtype: 'POST',
colNames: ['RID', l_('ProjectName'), l_('CustomerName'), l_('StartDate'), l_('EndDate'), l_('ManagerName'), l_('SourceLang'), l_('TargetLang'), l_('DomainName'), '', ''],
colModel: [
{ name: 'RID', index: 'RID', hidden: true, key: true },
{ name: 'ProjectName', index: 'ProjectName' },
{ name: 'CustomerName', index: 'CustomerName' },
{ name: 'StartDate', index: 'StartDate', width: '80px', align: 'center'},
{ name: 'EndDate', index: 'EndDate', width: '80px', align: 'center' },
{ name: 'FullName', index: 'FullName', align: 'center' },
{ name: 'SourceLang', index: 'SourceLang', width: '110px', align: 'center', formatter: flagFormatter },
{ name: 'TargetLang', index: 'TargetLang', width: '110px', align: 'center', formatter: flagFormatter },
{ name: 'DomainName', index: 'DomainName', width: '110px', align: 'center', formatter: domainNameFormatter },
{ name: 'IsExternal', index: 'IsExternal', hidden: true },
{ name: 'myac', fixed: true, sortable: false, resize: false, width: '30px'}],
height: '345px',
loaded: false,
shrinkToFit: false,
pager: '#projects_pager',
rowNum: 10,
autowidth: true,
rowList: [10, 20, 30],
viewrecords: true,
sortorder: 'desc',
altRows: true,
toolbar: [true, 'top'],
ExpandRowClick: true,
...some events (loadcomplete etc..)
和我的数据源一样:
<?xml version='1.0' encoding='utf-8'?>
<rows>
<page>1</page><total>1</total><records>4</records>
<row>
<cell>B55A6056261913D62648F2730C2766B2</cell>
<cell>Test Projectname1</cell>
<cell>Test Customer</cell>
<cell>18.02.2013</cell>
<cell>28.02.2013</cell>
<cell>Frank</cell>
<cell>en-GB</cell>
<cell>tr-TR</cell>
<cell>Law</cell>
<cell>0</cell>
<cell>0</cell>
<cell>0</cell>
<cell><![CDATA[NULL]]></cell>
<cell>true</cell>
<cell>false</cell>
</row>
<row>
<cell>21142DEE531B2313FC9356C3B000B54D</cell>
<cell>Test Projectname2</cell>
<cell>Test Customer</cell>
<cell>05.04.2013</cell>
<cell>06.04.2013</cell>
<cell>Frank</cell>
<cell>en-GB</cell>
<cell>tr-TR</cell>
<cell>Law</cell>
<cell>0</cell>
<cell>0</cell>
<cell>0</cell>
<cell><![CDATA[NULL]]></cell>
<cell>true</cell>
<cell>false</cell>
</row>
<row>
<cell>5FF805CE71B0A459C83734735B990E8C</cell>
<cell>Test Projectname3</cell>
<cell>Test Customer</cell>
<cell>22.04.2013</cell>
<cell>27.04.2013</cell>
<cell>Frank</cell>
<cell>en-GB</cell>
<cell>tr-TR</cell>
<cell>Law</cell>
<cell>0</cell>
<cell>0</cell>
<cell>0</cell>
<cell><![CDATA[NULL]]></cell>
<cell>false</cell>
<cell>false</cell>
</row>
<row>
<cell>BCD36ABFA07CE94089F6C5B743C57608</cell>
<cell>Test Projectname4</cell>
<cell>Test Customer</cell>
<cell>27.04.2013</cell>
<cell>28.04.2013</cell>
<cell>Frank</cell>
<cell>en-GB</cell>
<cell>tr-TR</cell>
<cell>Law</cell>
<cell>0</cell>
<cell>0</cell>
<cell>0</cell>
<cell><![CDATA[NULL]]></cell>
<cell>true</cell>
<cell>false</cell>
</row>
</rows>
所以我的问题是日期列排序。我已经在stackoverflow中进行了一些搜索,我发现了一些解决方案,但它们不起作用。
未排序的列表:
18.02.2013
05.04.2013
22.04.2013
27.04.2013
按此排序:
05.04.2013
18.02.2013
22.04.2013
27.04.2013
我错了什么?
答案 0 :(得分:0)
您应该在formatter: "date"
和formatoptions
列中使用'StartDate'
和'EndDate'
正确的22.04.2013
。当前设置(默认选项)通知jqGrid将数据解释为字符串。要以formatter: "date", formatoptions: { srcformat: "d.m.Y", newformat: "d.m.Y" }
等格式正确排序日期,您应在列定义中包含以下附加属性:
{{1}}