Showing posts with label ExtJS. Show all posts
Showing posts with label ExtJS. Show all posts

Friday, November 30, 2007

ExtJS Default Selection Model for EditorGridPanel

Just doing some playing around with selecting rows in the EditorGridPanel for ExtJS 2 and noticed that the API docs say for the selModel config attribute:
Any subclass of AbstractSelectionModel that will provide the selection model for the grid (defaults to Ext.grid.RowSelectionModel if not specified).

But when I was working away, I found that instead of the RowSelectionModel, I was actually getting a default CellSelectionModel. Any ideas?

Thursday, November 29, 2007

ExtJS 2 and JSR 311 (Jersey)

For a side project at work, I've been working on new UI components using ExtJS and powering this front-end with a JSR 311 (Jersey) back-end.

The other day I was able to get something working for the first time that has troubled me for a bit: dynamic saving of an EditorGridPanel. Basically, the EditorGridPanel gives you inline editing of a table, and then I trigger a save of this data through a REST call back to the server.

The front-end:

function updateUser(e) {
var thisUrl = '
/' + e.record.id;
var f = e.field;
var v = e.value;
var data = { 'field' : f, 'value' : v };
var p = Ext.util.JSON.encode(data);
Ext.Ajax.request({url: thisUrl, method: 'POST', params: p});
}


The back-end:

@HttpMethod("POST")
public void updateField(String body) throws JSONException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
JSONObject o = new JSONObject(body);
PropertyUtils.setSimpleProperty(user, o.getString("field"), o.get("value"));
RealmManager.instance().updateUser(user);
}


As might be obvious, this is to save some details about a user.

One thing I wasn't able to get working was the jsonData option for the Ajax.request call. Jersey would complain about media headers and what not that it couldn't convert into anything.

Wednesday, November 28, 2007

ExtJS 2 with Accordion Menu

I've been playing around with ExtJS for the last several weeks for a project at my work and just recently went through the process of upgrading out pages from ExtJS 1.x to 2. It was quite the experience and one of things that I found to be much easier was getting the Accordion menu working.

When we used 1.x we used the ux.Accordion menu system. But for 2 I decided to try out the built in Accordion menu.

Here's a taste of some of the code.

Before:
var acc = new Ext.ux.Accordion('acc-ct', {
fitHeight: false,
useShadow: true
})

// create accordian panels from existing DIVs
var panel1 = acc.add(new Ext.ux.InfoPanel('panel-1', {trigger:'title', draggable: true, resizable: true, collapsed:false}));
var panel2 = acc.add(new Ext.ux.InfoPanel('panel-2', {trigger:'title', draggable: true, resizable: true}));
var panel3 = acc.add(new Ext.ux.InfoPanel('panel-3', {trigger:'title', draggable: true, resizable: true}));
var panel4 = acc.add(new Ext.ux.InfoPanel('panel-4', {trigger:'title', draggable: true, resizable: true}));
var panel5 = acc.add(new Ext.ux.InfoPanel('panel-5', {trigger:'title', draggable: true, resizable: true}));
After:
var accordian = new Ext.Panel({
layout: 'accordion',
layoutConfig: {
titleCollapse: false,
animate: true,
fill: false
},
width: 200,
collapsible: true,
items: [
{
title: 'Panel 1',
html: 'Content'
},
{
title: 'Panel 2',
html: 'Content'
},
{
title: 'Panel 3',
html: 'Content'
},
{
title: 'Panel 4',
html: 'Content'
},
{
title: 'Panel 5',
html: 'Content'
}
],
renderTo: 'acc-ct'
});

As you can see, there are slight variations, but I prefer the new approach, even if it is much longer. It works well with ExtJS and their Panel layout which is nice. The only thing I don't like is that I don't know how to get the HTML content from an existing element on the page (like how ux.Accordion will convert DIV tags).