PDA

View Full Version : EditorGridPanel Questions



robertoroberto
5 Aug 2009, 10:37 PM
Hi
I have some questions about EditorGridPanel.

1) I must submit fields contained in the EditorGridPanel all together and using arrays.
I try to explain it...
If I have columns "A", "B", "C".... i should submit form sending "n" "A" fields, "n" "B" fields... "N" is the number of row.
So the backend recieve and array of "A", "B" and "C"
(this because I'm rewriting UI of an existing backend and I cannot change this behaviour)

How to do it ? What is the best way to do it ?
The only my (theoric) idea is to save before all row in the local store and after read the store and create fields to be submitted....


2) the backend thows exception for some field/row... how to mark as invalidat a field in a specific row ?
In a FormPanel I can invoke the markInvalidate method... but I haven't idea in a Grid.

Thanks!

tubamanu
5 Aug 2009, 10:57 PM
hi,

do u only want to submit the changed rows from client to server ? oder do u want to save the whole store on serverside?

how is the structrue of the array serverside?

robertoroberto
5 Aug 2009, 11:26 PM
I need to submit ALL rows also if they are not changed.

Each column is an array.


If I have columns "A", "B", "C".... i must submit form sending "n" "A" fields, "n" "B" fields... "N" is the number of row.
So the backend recieve and array of "A", "B" and "C"


It is exactly the same behaviour if you have a simulated Grid done with an HTML Table
e.g.



<table>
<tr>
<td><input type="text" name="A" id="A" /></td>
<td><input type="text" name="B" id="B" /></td>
</tr>
<tr>
<td><input type="text" name="A" id="A" /></td>
<td><input type="text" name="B" id="B" /></td>
</tr>
<tr>
<td><input type="text" name="A" id="A" /></td>
<td><input type="text" name="B" id="B" /></td>
</tr>
</table>

tubamanu
5 Aug 2009, 11:41 PM
maybe this is interesting for you:

http://extjs.com/forum/showthread.php?t=55406

u can add to your grid a toolbar with a saveicon, that calls a ajaxfunction, that stores all records to your database.

if u submit your html-table example, on serverside u will only get the content of the last textfield, not of the 2 above them.
so your array on serverside is like this?


$_REQUEST['A'][0] = 'val1';
$_REQUEST['A'][1] = 'val2';
$_REQUEST['A'][2] = 'val3';

robertoroberto
6 Aug 2009, 1:12 AM
Ty tubamano
But you are making a big mistake...


if u submit your html-table example, on serverside u will only get the content of the last textfield, not of the 2 above them

This is not true..
You must use the propertly way on the server side and you will get an array of "B" or "A"...
it is exactly the same way if instead to use a POST, you are using a GET and pass arguments like :


http://www.extjs.com/forum.asp?attr1=1&a=hello&a=world

if you get in the property way the "A" values, you will recieve an Array of "A"

e.g. using java (Servlet or JSP)


request.getParameterValues("A");

this returns a String[]

bye

tubamanu
6 Aug 2009, 1:23 AM
ah okay :)
then there is no problem when using ext to rebuild the url u need. maybe u can use this, to store your data, i used this to update modified records in database....



handler : function(t){
var eds = grid.getStore().getModifiedRecords(); // u need to find a get all function
if(eds.length > 0) {
for(var i=0; i < eds.length;i++){
var r = eds[i];
var id = r.get('id'); // id of the current record
var name = r.get('username'); // username of the current record
var updateurl = 'index.php?&id='+id; // rebuild your url here
updateurl = encodeURI(updateurl);
Ext.Ajax.request({
url : updateurl
});
store.commitChanges();
}
if (eds.length == 1) {
Ext.Msg.alert('OK', '1 Datensatz ge&auml;ndert');
}
else {
Ext.Msg.alert('OK', eds.length + ' Datens&auml;tze ge&auml;ndert');
}
}
}

Condor
6 Aug 2009, 1:26 AM
1. First question:

// Collect the data from the grid store
var params = {};
grid.getStore().each(function(r, i){
for(var p in r.data){
if(r.data.hasOwnProperty(p)){
var param = params[p];
if(!param){
param = params[p] = [];
}
param[i] = r.data[p];
}
}
});
// Send request with data
Ext.Ajax.request({
url: 'myurl',
params: params,
success: function(){...},
failure: function(){...}
});

2. Second question:
You could add an extra field to your store that would contain if the record was invalid or not.
Next, you could write an getRowClass method that shows invalid records in a different color.

robertoroberto
6 Aug 2009, 1:31 AM
TY Condor.

About question 1: great. This is the best solution I think (in my cases)

About question 2:
I should mark not only that a Row contains invalid data.. but also mark the specific cell

ty

Condor
6 Aug 2009, 2:38 AM
As said, GridPanel has not 'error' support build in (I once write an extension to support showing invalid entries in an EditorGridPanel).

You'll have to remember in the store which fields are invalid and write a custom renderer to show the cells as invalid.