I'm having some serious trouble finding a solution to this problem:
My Store object does not change, even if I change the data in the
grid.
Here's what I'm trying to do:
Based on a parameter, I use a specific RecordDef for creating the
proxy, reader, etc. For testing purposes, I'm now running with this
code:
<pre class="brush: java">
package com.accenture.piriam.gui.client.widgets;
import com.accenture.piriam.model.client.GraphType;
import com.google.gwt.core.client.GWT;
import com.gwtext.client.core.TextAlign;
import com.gwtext.client.data.*;
import com.gwtext.client.widgets.*;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.form.*;
import com.gwtext.client.widgets.grid.*;
import com.gwtext.client.core.EventObject;
public class InputEditorGrid extends EditorGridPanel {
private final RecordDef recordDefPie = new RecordDef(new FieldDef[]
{ new StringFieldDef("category"),
new FloatFieldDef("value"), new
StringFieldDef("color"), new
FloatFieldDef("explosion") });
private Object[][] data;
private GraphType type;
public InputEditorGrid(final GraphType type, Object[][] input) {
super();
this.type = type;
if (input == null)
data = getStdData();
else
data = input;
// TODO: make this use colorpicker
SimpleStore colors = new SimpleStore("colors", new String[]
{ "Blue", "Orange", "Black", "Grey", "Yellow" });
colors.load();
ColumnConfig categoryCol = new ColumnConfig("Category",
"category",
220, true, null, "category");
categoryCol.setEditor(new GridEditor(new TextField()));
ColumnConfig valueCol = new ColumnConfig("Value", "value", 80,
true,
null, "value");
valueCol.setEditor(new GridEditor(new TextField()));
valueCol.setAlign(TextAlign.RIGHT);
NumberField numberField = new NumberField();
numberField.setAllowBlank(false);
numberField.setAllowNegative(true);
valueCol.setEditor(new GridEditor(numberField));
ColumnConfig colorCol = new ColumnConfig("Color", "color", 130);
final ComboBox cb = new ComboBox();
cb.setDisplayField("colors");
cb.setStore(colors);
colorCol.setEditor(new GridEditor(cb));
ColumnConfig explosionCol = new ColumnConfig("Explosion",
"explosion", 80, true, null, "explosion");
explosionCol.setAlign(TextAlign.RIGHT);
NumberField enumberField = new NumberField();
enumberField.setAllowBlank(false);
enumberField.setAllowNegative(true);
explosionCol.setEditor(new GridEditor(enumberField));
ColumnConfig[] configs = new ColumnConfig[] { categoryCol,
valueCol,
colorCol, explosionCol };
MemoryProxy proxy = new MemoryProxy(data);
ArrayReader reader = new ArrayReader(recordDefPie);
ColumnModel columnModel = new ColumnModel(configs);
columnModel.setDefaultSortable(true);
Store store = new Store(proxy, reader);
store.load();
setStore(store);
Toolbar toolbar = new Toolbar();
ToolbarButton button = new ToolbarButton("Add line", new
ButtonListenerAdapter() {
public void onClick(Button button, EventObject e) {
Record newRecord;
newRecord = recordDefPie.createRecord(new
Object[] { "", 0,
"Black", 0 });
stopEditing();
getStore().insert(getStore().getCount(),
newRecord);
startEditing(getStore().getCount()-1, 0);
GWT.log("Record inserted. Now contains
"+getStore().getCount()+ "
records", null);
}
});
button.setStyle("toolbar-btn");
ToolbarButton button2 = new ToolbarButton("Delete line", new
ButtonListenerAdapter() {
public void onClick(Button button, EventObject e) {
int[] selectedLines =
getCellSelectionModel().getSelectedCell();
if (selectedLines == null)
return;
stopEditing();
getStore().remove(getStore().getAt(selectedLines[0]));
if (getStore().getCount() != 0)
startEditing(0, 0);
}
});
button2.setStyle("toolbar-btn");
toolbar.addButton(button);
toolbar.addButton(button2);
setColumnModel(columnModel);
int calcWidth = 0;
for (int i = 0; i < configs.length ; i++)
calcWidth += configs[i].getWidth();
setWidth(calcWidth+10);
setHeight(300);
//setAutoExpandColumn("category");
setTitle("Data");
setFrame(true);
setClicksToEdit(1);
setBottomToolbar(toolbar);
}
private Object[][] getStdData() {
return new Object[][]{
{"Test", 1.0, "blue", 0.1},
{"Test2", 1.0, "blue", 0.1}
};
}
public Object[][] getData()
{
getStore().commitChanges();
Record[] records = getStore().getRecords();
GWT.log("Changes committed. There are "+records.length + "
lines in
data array "+ getStore().getCount(), null);
// dont mind the following line - I know that one does not work.
return data;
}
}
</pre>
My output:
When I start up the program the correct two lines are displayed in the
grid. Then I remove one of them, and I call getData(). I get this
output;
[INFO] Changes committed. There are 2 lines in data array 2
I then add two lines, getting this feedback;
[INFO] Record inserted. Now contains 2 records
[INFO] Record inserted. Now contains 3 records
I now call getData() again:
[INFO] Changes committed. There are 2 lines in data array 2
In short - none of my changes seem to "stick". If I press "add line"
again, I get
[INFO] Record inserted. Now contains 4 records
A third call to getData() reveals that the records are not really
added to whatever store this method has access to:
[INFO] Changes committed. There are 2 lines in data array 2
So, I can alter the values, but not get a hold of them afterwards -
which makes it pretty useless to alter them.
The REALLY weird thing, though is that getStore().getCount() returns
two different values in the two methods.
What I have tried so far:
- Omitting the commitChanges() call, and relying on the
getModifiedRecords() method. No effect.
- not using a data array to initialize the Store, just a RecordDef. No
effect.
- using an Xml file to back the store. No effect.
- pulling out hair. No effect.
- trying various configurations of store.getModifiedRecords(),
getRecords(), getCount() and getTotalCount(). No effect.
- Passing a null variable as data (runtime error).
- moving the variable into a field, avoiding the call to getStdData().
No effect.
- switching to gwt-ext version 2.0.4 (as suggested here :
http://www.gwt-ext.com/forum/viewtopic.php?f=8&t=2774 ). No Effect.
- making store a final field, and accessing it directly. No Effect.
Can you spot what I have missed ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"GWT-Ext Developer Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/gwt-ext?hl=en
-~----------~----~----~----~------~----~------~--~---