我有下面的(工作)代码初始化GXT 3 Grid以显示2个日期列(已完成和到期)和一个布尔列(适用)。它配置为内联编辑并通过检查某些条件并根据这些条件对其他列进行操作来处理“已完成编辑”事件。所有好东西。
我只是无法弄清楚如何执行以下操作:如果布尔字段为false,则禁用日期字段(反之亦然)。我需要在使用数据初始化网格和用户与布尔字段的交互时执行此操作。
一些遗漏的代码是由下面的评论“持有人怎么做?”
private void initializeColumnModel() {
// Create the configurations for each column in the grid
List<ColumnConfig<Reminder, ?>> ccs = new LinkedList<ColumnConfig<Reminder, ?>>();
typeColumnConfig = new ColumnConfig<Reminder,String>( properties.name(), 120, ColumnDescriptor.TYPE.getName() );
completedColumnConfig = getDateCellColumn( properties.completed_(), 200, ColumnDescriptor.COMPLETED.getName() );
dueColumnConfig = getDateCellColumn( properties.due_(), 200, ColumnDescriptor.DUE.getName() );
applicableColumnConfig = new ColumnConfig<Reminder,Boolean>( properties.applicable(), 140, ColumnDescriptor.APPLICABLE.getName() );
// Add column configurations to ColumnModel in specified order.
ccs.add(ColumnDescriptor.TYPE.ordinal(), typeColumnConfig);
ccs.add(ColumnDescriptor.COMPLETED.ordinal(), completedColumnConfig);
ccs.add(ColumnDescriptor.DUE.ordinal(), dueColumnConfig);
ccs.add(ColumnDescriptor.APPLICABLE.ordinal(), applicableColumnConfig);
applicableColumnConfig.setAlignment(HasHorizontalAlignment.ALIGN_CENTER);
typeColumnConfig.setAlignment(HasHorizontalAlignment.ALIGN_CENTER);
reminderColumnModel = new ColumnModel<Reminder>(ccs);
}
private ColumnConfig<Reminder,Date> getDateCellColumn(
ValueProvider<Reminder,Date> colDateProvider,
int width,
String name) {
SafeStyles fieldPaddingStyle = SafeStylesUtils.fromTrustedString("padding: 2px 3px;");
ColumnConfig<Reminder, Date> dateColumn = new ColumnConfig<Reminder, Date>(colDateProvider, width, name);
dateColumn.setColumnTextStyle(fieldPaddingStyle);
return dateColumn;
}
private DateField getDateField(){
DateField dateField = new DateField(new DateTimePropertyEditor(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT)));
dateField.setClearValueOnParseError(false);
return dateField;
}
@Override
public Widget asWidget() {
if(!gridInitialized){
editing = new GridInlineEditing<Reminder>(grid);
DateField dueDateField = getDateField();
DateField completedDateField = getDateField();
CheckBox applicBox = new CheckBox();
editing.addEditor(dueColumnConfig, dueDateField);
editing.addEditor(completedColumnConfig, completedDateField);
editing.addEditor(applicableColumnConfig, applicBox);
editing.addCompleteEditHandler(new CompleteEditHandler<Reminder>(){
@Override
public void onCompleteEdit(CompleteEditEvent<Reminder> event) {
GridCell cell = event.getEditCell();
int row = cell.getRow();
int col = cell.getCol();
Reminder rem = reminderStore.get(row);
Store<Reminder>.Record rec = reminderStore.getRecord(rem);
Change<Reminder, Boolean> applicChange = rec.getChange(properties.applicable());
Change<Reminder, Date> dueChange = rec.getChange(properties.due_());
Change<Reminder, Date> comChange = rec.getChange(properties.completed_());
System.err.println("Row "+(row+1)+" changed: ");
if(col==ColumnDescriptor.APPLICABLE.ordinal()){
if(applicChange!=null){
boolean applicValue = applicChange.getValue();
enableDateFieldsForRow(applicValue, row);
System.out.println(" applicable changed to "+applicValue);
}
else{
enableDateFieldsForRow(rem.getApplicable(), row);
System.out.println(" applicable reverted to "+rem.getApplicable());
}
}
if(col==ColumnDescriptor.DUE.ordinal()){
if(dueChange!=null ){
Date dueValue = dueChange.getValue();
System.out.println(" due changed to: "+SimpleDate.convertFromDate(dueValue));
}
else
System.out.println(" due reverted to "+rem.getDue());
}
if(col==ColumnDescriptor.COMPLETED.ordinal()){
if(comChange!=null ){
Date comValue = comChange.getValue();
System.out.println(" com changed to: "+SimpleDate.convertFromDate(comValue));
try{
fixDueDate(row,comValue, rem, rec);
}
catch(Exception e){
//boo.
System.err.println("Could not update the due date for this completion date change.");
}
}
else
System.out.println(" due reverted to "+rem.getCompleted());
}
}
});
gridInitialized=true;
}
// Initialize the Revert Changes button.
revert.addSelectHandler(new SelectHandler(){
@Override
public void onSelect(SelectEvent event) {
reminderStore.rejectChanges();
}
});
// ok, now, return the widget!
return widget;
}
// Enable/disable date fields based on whether they are applicable (applicValue).
private void enableDateFieldsForRow(boolean applicValue, int row){
// ** HOW DO YOU DO THIS? ***
}
private void fixDueDate(int row, Date completedDate, Reminder rem, Store<Reminder>.Record rec )
throws InvalidDateFormatException, InvalidDateException{
SimpleDate newCompDate = new SimpleDate(completedDate);
SimpleDate dueDate = newCompDate.addYears(rem.getRenewalYears());
rec.addChange(dueColumnConfig.getValueProvider(), dueDate.toDate());
}
public List<Reminder> getModifications(){
System.out.println("grid modifications:");
List<Reminder> modified = new ArrayList<Reminder>();
for(Store<Reminder>.Record record : reminderStore.getModifiedRecords()){
Reminder model = record.getModel();
Reminder clone = model.clone();
for(Change<Reminder,?> change : record.getChanges()){
change.modify(clone);
}
modified.add(clone);
}
return modified;
}
public List<Reminder> commitChanges(){
reminderStore.commitChanges();
return reminderStore.getAll();
}
public void updateList(List<Reminder> list){
reminderStore.clear();
for(Reminder r : list){
reminderStore.add(r);
}
// disable selection of rows.
grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
//grid.disableEvents();
}
感谢。
答案 0 :(得分:0)
我也遇到了同样的问题,在Grid中禁用和启用单元格。但我正在使用GXT 2.2.3的EditorGrid。经过多次尝试,我得到了一个解决方案,而不是考虑禁用和启用单元格,我只需使用CSS隐藏和显示单元格。以下是我的代码,可以帮助我满足这一要求。
GridCellRenderer<AttendanceCaseCreationModel> checkinRenderer=new GridCellRenderer<AttendanceCaseCreationModel>() {
@Override
public Object render(AttendanceCaseCreationModel model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<AttendanceCaseCreationModel> store,
Grid<AttendanceCaseCreationModel> grid) {
String color="pink";
if(eventcombo.getValue()!=null){
if(eventcombo.getRawValue().equalsIgnoreCase("Forgot To Checkin") ||
eventcombo.getRawValue().equalsIgnoreCase("Mark/Modify Attendance")){
color="pink";
}
else{
config.style=config.style+ ";visibility: hidden;";
}
}
config.style=config.style+ ";background-color:" + color + ";";
config.style=config.style+ ";display: block;";
Object value = model.get(property);
return value;
}
};