【发布时间】:2014-07-04 07:31:18
【问题描述】:
在 GXT Grid 中,我尝试使用 RowEditing 和 CheckBoxSelectionModel。 Sencha Explorer Demo 在Row Editable Grid 和CheckBox Grid 示例中有这些示例,但它们没有显示包含这些功能组合的示例。当我在同一个网格上使用这两个功能时,我没有得到我预期的行为。如果我单击“选择”复选框,则该行将进入编辑模式,我预计该复选框只会从选中变为未选中,反之亦然。此外,当该行进入编辑模式时,该行存在损坏。这是在单击该行中的任何值之前网格中的一行的示例:
这是单击其中一个值后的那一行:
有人有这方面的经验吗?
更新
这是一个演示问题的示例类:
package org.greatlogic.gxtgrid.client;
import java.util.ArrayList;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.sencha.gxt.core.client.IdentityValueProvider;
import com.sencha.gxt.core.client.ValueProvider;
import com.sencha.gxt.data.shared.ListStore;
import com.sencha.gxt.data.shared.ModelKeyProvider;
import com.sencha.gxt.widget.core.client.ContentPanel;
import com.sencha.gxt.widget.core.client.form.TextField;
import com.sencha.gxt.widget.core.client.grid.CheckBoxSelectionModel;
import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
import com.sencha.gxt.widget.core.client.grid.Grid;
import com.sencha.gxt.widget.core.client.grid.GridView;
import com.sencha.gxt.widget.core.client.grid.editing.GridRowEditing;
public class GXTGrid implements EntryPoint {
//-------------------------------------------------------------------------
@Override
public void onModuleLoad() {
ListStore<Pet> listStore = new ListStore<>(new ModelKeyProvider<Pet>() {
@Override
public String getKey(Pet pet) {
return Integer.toString(pet.getPetId());
}
});
IdentityValueProvider<Pet> ivp = new IdentityValueProvider<>();
CheckBoxSelectionModel<Pet> sm = new CheckBoxSelectionModel<>(ivp);
ArrayList<ColumnConfig<Pet, ?>> ccList = new ArrayList<>();
ccList.add(sm.getColumn());
ColumnConfig<Pet, String> cc1;
cc1 = new ColumnConfig<>(Pet.getPetNameValueProvider(), 100, "Name");
ccList.add(cc1);
ColumnModel<Pet> columnModel = new ColumnModel<>(ccList);
Grid<Pet> grid = new Grid<>(listStore, columnModel);
grid.setSelectionModel(sm);
grid.setView(new GridView<Pet>());
GridRowEditing<Pet> gre = new GridRowEditing<>(grid);
gre.addEditor(cc1, new TextField());
listStore.add(new Pet(1, "Lassie"));
listStore.add(new Pet(2, "Scooby"));
listStore.add(new Pet(3, "Snoopy"));
ContentPanel contentPanel = new ContentPanel();
contentPanel.add(grid);
RootLayoutPanel.get().add(contentPanel);
}
//-------------------------------------------------------------------------
private static class Pet {
private int _petId;
private String _petName;
public static ValueProvider<Pet, String> getPetNameValueProvider() {
return new ValueProvider<Pet, String>() {
@Override
public String getPath() {
return "Pet.PetName";
}
@Override
public String getValue(Pet pet) {
return pet._petName;
}
@Override
public void setValue(Pet pet, final String value) {
pet._petName = value;
}
};
}
public Pet(int petId, final String petName) {
_petId = petId;
_petName = petName;
}
public int getPetId() {
return _petId;
}
}
//-------------------------------------------------------------------------
}
【问题讨论】:
-
你能提供你的代码吗?你会得到更多更好的答案。
-
@RadASM 代码相当广泛,但您可以使用Sencha GXT Explorer Demo 中的Sencha Row Editable Grid 示例并将
CheckBoxSelectionModel添加到其中以查看问题。您是否在使用RowEditing和CheckBoxSelectModel选项的网格上取得了成功? -
我习惯了 inlineRowEditing。所以基本上我已经使用 gxt 一段时间了,我可能会提供帮助。一种可能对您有所帮助(不是解决问题而是避免问题)的想法不是单击单元格而是双击开始编辑。 gridRowEditing.setClicksToEdit(ClicksToEdit.TWO);很抱歉,没有看到源代码,我想我不能给你更多的帮助。
-
@RadASM 谢谢...我将创建一个(相对)小的测试用例并用代码更新我的问题。
标签: gxt