简体   繁体   English

GWT(smartgwt)网格对所选记录进行排序

[英]GWT (smartgwt) grid sort selected records top

I have a grid where the user can select records via checkbox in front of every record. 我有一个网格,用户可以在其中通过每个记录前面的复选框选择记录。 Now I have a requirement to sort the records based on their selection, so that all selected records should be placed top, followed by the not selected ones. 现在,我需要根据记录的选择对记录进行排序,以便将所有选择的记录放在最前面,然后是未选择的记录。

Is there any standard function to achieve this? 是否有任何标准功能可以实现这一目标? As an alternative I thought of saving the selection state as an attribute on every record and sort based on the attribute. 作为替代方案,我想到了将选择状态保存为每个记录的属性,并根据该属性进行排序。

The code for the column is: 该列的代码是:

gridRealmDt.setSelectionType(SelectionStyle.SIMPLE);
gridRealmDt.setSelectionAppearance(SelectionAppearance.CHECKBOX);

I try to describe the code I use as the affected code is deeply nested in our own framework classes. 我尝试描述我使用的代码,因为受影响的代码深深地嵌套在我们自己的框架类中。
gridRealmDt is a subclass of smartgwt ListGrid. gridRealmDt是smartgwt ListGrid的子类。 In my Dialog a create an instance of the grid which creates an instance of a database bound datasource. 在我的对话框中,创建一个网格实例,该实例创建一个数据库绑定数据源的实例。 When the dialog is loaded the records are fetched from the database and after that a registered an dataArrivedHandler where I select the records which match records from another table. 加载对话框后,将从数据库中获取记录,然后注册一个dataArrivedHandler,在其中我选择与另一个表中的记录匹配的记录。

I tried to place the selection attribute in an extra field and use that for sortig before my other sort criteria, but this does not work. 我试图将选择属性放在一个额外的字段中,并在其他排序标准之前将其用于sortig,但这是行不通的。 Here is the code for the field I am using. 这是我正在使用的字段的代码。

ListGridField txtSelected = new ListGridField(SELECTED, "");
txtSelected.setHidden(true);
txtSelected.setSortByDisplayField(true);
txtSelected.setCanSortClientOnly(true);

When I do not set the canSortClientOnly property the order by is sent to my database resulting in an error, as the table does not contain that field, so I set the property. 当我不设置canSortClientOnly属性时,由于表不包含该字段,因此将订单发送到我的数据库,导致错误,因此我设置了该属性。 Now I get following error 现在我得到以下错误

Removing field from the sort Specifier array because it specifies canSort Client Only: true and all data is not yet client-side. 从sort Specifier数组中删除字段,因为它指定canSort Client Only:true,并且所有数据还不是客户端。

I also tried to use a sortNormilizer on the Name field which is my main sort criteria, but the normalizer is called before the selection value is set to the record. 我还尝试在“名称”字段上使用sortNormilizer,这是我的主要排序条件,但是在将选择值设置为记录之前调用了规范化程序。

record.setAttribute(CARealmDS.SELECTED,selected ? "a" : "b");

I also cannnot find a way to call the normalizer when selection changes. 当选择更改时,我也找不到调用标准化器的方法。

Currently we are using Smart GWT Version 6.0p. 当前,我们正在使用Smart GWT 6.0p版本。

I don't think there is any standard function. 我认为没有任何标准功能。 Just use grid store update. 只需使用网格存储更新。 Place checked items first. 首先放置检查项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM