PDA

View Full Version : server-side columnModel



service@think-1st.de
12 Jan 2009, 8:18 AM
Hi
Sometimes I need to create a grid in which I don't know how many columns should it have.
The only way to achieve this is with Autogrid user extension (http://extjs.com/forum/showthread.php?t=10951). Currently I think that its features are limited and its documentation is not well defined.

Could you implement something like this?

service@think-1st.de
13 Jan 2009, 10:09 AM
Is there a plan to work on this issue in a near future?

Thanks.

jay@moduscreate.com
13 Jan 2009, 10:49 AM
they are working hard on getting 3.0 stable and ready for GA, don't be surprised if they don't answer right away!!

mjlecomte
13 Jan 2009, 11:06 AM
What is it that you think could be done? A hook is provided via sending back metaData. You might find better chance for success if you're more specific with your request is all I'm saying.

service@think-1st.de
13 Jan 2009, 12:28 PM
What is it that you think could be done? A hook is provided via sending back metaData. You might find better chance for success if you're more specific with your request is all I'm saying.

I'm asking for a workaround to define columnModels on the server side.
There is one provided by JorisA (the link from my first post), but this code is not stable/complete. Currently I'm not able to define a checkbox with this approach, so I will appreciate if someone could help me with this.

I think that this workaround should be part of extjs distribution.

evant
13 Jan 2009, 3:08 PM
You can quite easily do something like this though:



Ext.Ajax.request({
url: 'foo',
success: function(response){
var cols = Ext.decode(response.responseText);
myGrid.reconfigure(myGrid.getStore(), new Ext.grid.ColumnModel(cols));
}
});

mjlecomte
13 Jan 2009, 3:34 PM
I think the OP had posted in another thread which he did not link. I believe the OP was having difficulty getting checkboxes to work in the grid via remote configuration via metadata.

service@think-1st.de
13 Jan 2009, 7:45 PM
You can quite easily do something like this though:



Ext.Ajax.request({
url: 'foo',
success: function(response){
var cols = Ext.decode(response.responseText);
myGrid.reconfigure(myGrid.getStore(), new Ext.grid.ColumnModel(cols));
}
});


Your approach could solve my problem, but I found a problem.
By defining a new store, I need to create a JsonReader, this JsonReader must have its Ext.data.Record constructor.
In my case, I don't know how many columns the grid could have ( yes, I can fetch them from the server ), but how could I define Ext.data.Record constructor when I don't know its records ?

Currently I have this:





//Ext.data.Record constructor, in this case this is defined and it's not fetched from the server, could I take it from the server?
var recordObjEinkaufsdatenGrid = Ext.data.Record.create([
{name: 'Kurztext'},
{name: 'EinstandswertMaterial', type: 'float'},
{name: 'EinstandswertLohn', type: 'float'},
{name: 'EinstandswertFremdlohn', type: 'float'},
{name: 'EinstandswertEp3', type: 'float'},
{name: 'Materialgruppe', type: 'float'},
]);



var columnModel = new Ext.grid.ColumnModel([
{id: 'EinstandswertLohn', header: 'EinstandswertLohn', sortable: true, dataIndex: 'EinstandswertLohn'},
{id: 'EinstandswertMaterial', header: 'EinstandswertMaterial', sortable: true, dataIndex: 'EinstandswertMaterial'},
{id: 'Materialgruppe', header: 'Materialgruppe', sortable: true, dataIndex: 'Materialgruppe'}
]);

var readerEinkaufsdatenGrid = new Ext.data.JsonReader(
{
root: 'results',
totalProperty: 'total',
id: 'ImpDatId'
}
,recordObjEinkaufsdatenGrid//this is the record contructor
);


var dsEinkaufsdatenGrid = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: '../transactions/buy.buydata.php',
method: 'POST'
}),
baseParams:{
// Parameter send to PHP
task: "loadEinkaufsdatenGrid",
typesearch: 'Kurztext',
extmatch: 1,
limit:130,
start:0,
fileid:31

},
reader: readerEinkaufsdatenGrid
});//eo dsEinkaufsdatenGrid

Ext.getCmp('columnRights_panel').reconfigure(dsEinkaufsdatenGrid , columnModel ) ;
dsEinkaufsdatenGrid.load();

The above code works.
If I change the columnModel ( I mean to define different columns ) and reload the ds, the grid is loaded with new data and new columns, but in this case I know which columns could I load because I know the Ext.data.Record constructor

mjlecomte
13 Jan 2009, 8:30 PM
I'm confused because in the other thread I thought I recall you saying you're getting the fields from metaData and then you can do the reconfigure. When you pass the fields in, it creates the record constructor for you.

I thought your hitch was checkboxes?

I presumed you weren't using Joris A code but something more similar to what I posted where I do as described, take metaData, get fields, apply any listeners, editors, plugins, and then reconfigure.

service@think-1st.de
14 Jan 2009, 5:41 AM
I'm confused because in the other thread I thought I recall you saying you're getting the fields from metaData and then you can do the reconfigure. When you pass the fields in, it creates the record constructor for you.

I thought your hitch was checkboxes?

I presumed you weren't using Joris A code but something more similar to what I posted where I do as described, take metaData, get fields, apply any listeners, editors, plugins, and then reconfigure.

In this thread I didn't post the Autogrid code provided by JorisA, I just posted some code that I used to test the reconfigure issue.
Here I just tested the approach that evant wrote, but I found a problem ( constructor ). Ok, in the code above I defined the columnModel and I didn't fetch it from the server.

In my app I'M using the Autogrid extension, the one created by JorisA and no other ( actually it was updatded by you :) )

Here is the last post I wrote about this extension: http://extjs.com/forum/showthread.php?t=10951&page=13

In this thread you're telling my which steps follow to create the columnModel from metaData (using Autogrid), I did what you wrote but I'm making an error don't know where when I want to define checkboxes.

Maybe reconfigure is other option to achieve what I want, I don't know, but currently I have the constructor problem.

Thanks