PDA

View Full Version : Must be simple: Make row in UIView pre-selected - but how?



Grendel
14 Feb 2008, 8:30 AM
I

RWaters
14 Feb 2008, 10:06 AM
Off the top of my head, I would try something like this:


view.grid.getStore().on('load', function() {
this.getSelectionModel().selectFirstRow();
}, view.grid);

Grendel
14 Feb 2008, 11:51 AM
Thanks, but where do I put that code? If I write



Ext.onReady( function() {
var view = new Ext.nd.UIView( {
viewName: 'recipies',
gridConfig: {
renderTo: 'viewdiv',
width: 500,
height: 500
}
});
view.grid.getStore().on('load', function() { this.getSelectionModel().selectFirstRow();}, view.grid);
});


I get an error "grid is null or not an object". Seems I

RWaters
14 Feb 2008, 11:56 AM
Ahh yes, that does make sense because we don't technically create the grid until we get the readviewentries call back.... For our next release I'll look into tacking on some events to UIView to simplify that.

Right now there's not an easy way to attach that handler without hacking into the UIView createGrid method.

bhaidaya
14 Feb 2008, 12:50 PM
you could use listeners when instantiating the grid like so: (as long as they are passed)


Ext.onReady( function() {
var view = new Ext.nd.UIView( {
viewName: 'recipies',
gridConfig: {
renderTo: 'viewdiv',
width: 500,
height: 500,
listeners:{'load':{fn:function() { this.getSelectionModel().selectFirstRow();} } }
}
});
});

I didn't test btw..

RWaters
14 Feb 2008, 1:20 PM
we do pass the gridConfig along to the grid, but unforunately we need to attach the listener to the datastore beacuse the gridpanel does not have a 'load' event..

bhaidaya
14 Feb 2008, 1:29 PM
good point.. how about something like this?

Ext.onReady( function() {
var view = new Ext.nd.UIView( {
viewName: 'recipies',
gridConfig: {
renderTo: 'viewdiv',
width: 500,
height: 500,
listeners:{'render':{fn: function(){
this.store.on('load', function(){
getSelectionModel().selectFirstRow();
})
}}}
}
});
});

Grendel
14 Feb 2008, 2:00 PM
good point.. how about something like this?

Ext.onReady( function() {
var view = new Ext.nd.UIView( {
viewName: 'recipies',
gridConfig: {
renderTo: 'viewdiv',
width: 500,
height: 500,
listeners:{'render':{fn: function(){
this.store.on('load', function(){
getSelectionModel().selectFirstRow();
})
}}}
}
});
});

Wow, that was clever code! Thanks bhaidaya! I can

jratcliff
14 Feb 2008, 2:22 PM
Great collaborative effort gang! I just did basically the same thing that Grendel did with bhaidaya's code fixing the scope issue.

So here's basically the same code but as an example using DominoUI with an outline and a view defined:


var ExtndApp = function() {
return {
init : function(){
this.ui = new Ext.nd.DominoUI({
uiOutline : {
outlineName: 'mainOL'
},
uiView : {
viewName: 'f1',
viewTitle: 'A Flat View Example',
showSearch: 'true',
gridConfig : {
listeners: {render : {fn: function() {
var grid = this;
this.getStore().on('load', function() {
this.getSelectionModel().selectFirstRow();
}, grid)
}}}
}
}
});
} // init
} // return
}();

Ext.onReady(ExtndApp.init, ExtndApp, true);


And here's an example of it in action:
http://openntf.org/extnd/demo.nsf/main-example-select-first-row.html

bhaidaya
14 Feb 2008, 3:32 PM
Nice! Glad it worked..

DigitalSkyline
14 Feb 2008, 6:57 PM
I have a somewhat related question, I need to pre-select a specific row on the panel activation. This is all good and well, but selectRecords apparently expects an array of records, not a single record.... I'm sure this is something simple, but I'm running out of caffiene!~o)I-| Any help is appreciated!




activate: function(gd){
if (currentContact) {
gd.getSelectionModel().selectRecords(gd.getStore().getById( currentContact ));
}
}


The problem

jratcliff
14 Feb 2008, 7:13 PM
Can you just add brackets around your call that returns a single record? I think that will then return an array of records (which happens to only have one item, but at least now it's an array)




activate: function(gd){
if (currentContact) {
gd.getSelectionModel().selectRecords([gd.getStore().getById( currentContact )]);
}
}

DigitalSkyline
14 Feb 2008, 7:48 PM
Yeah I tried that once, but it turns out that the record simply wasn't being populated by getById() --- because I neglected to define the id column in the reader, oops!

[ was needed, too btw ]

Thanks, it's working now!

jratcliff
14 Feb 2008, 8:08 PM
Awesome! Glad to hear you got it working then! =D>

Mike Amberg
26 Feb 2008, 1:58 PM
Jack

You need some examples for dummies (me) ...

I had a heck of a time figuring out how to implement this in my application ... even with your code. So using the Main.html page as in the extnd_b1 (v.2.01) ...

1) I was using the detailed HTMLHeaderContent see screenshot (not the single line version) ... I had to remove the high-lighted script that fired up the Domino-UI.

2) I added your code to the JS Header section, and now the Domino-UI is started from there.

I hadn't realized the "cookie - cutter" code in the profile document was launching the UI.

jratcliff
26 Feb 2008, 9:40 PM
Hmm, thanks for pointing that out. Rich and I will try and back the application profile form in the Ext.nd Admin database a little more clearer of what can be copied and pasted where.

Thanks for the feedback! Keep it coming. :)