hi jim,
is it this what you want? the following code has two arrays at the
top, "mycols" and "mydata". the rest of the code displays this data in
a listview, and if you select it displays the column/data of the
selected item.
the code never references ANY column name, you can simply change the
values in "mycols" (the columns) and the code runs with this names.
as you can see, i "mark" the usercolumns with a specific PREFIX, so i
can decide in my change-listener, which attribute of the selected item
is from my data.
and the code always uses type "text".
cu
</usc>
<html>
<head>
<script type="text/javascript"
src="http://localhost/qooxdoo/script/qooxdoo.js"></script>
</head>
<body>
<script>
var mycols = new Array ("id","attribute1","attribute2");
var mydata = new Array(
new Array ("1","abc","def"),
new Array ("2","ghi","jkl")
);
var PREFIX = "__my__"
var my_colheader = new Object ();
for (var i=0; i<mycols.length; i++) {
var col = {label:mycols[i], type:"text", width:100};
my_colheader[PREFIX+mycols[i]] = col;
}
var my_data = new Array ();
for (var i=0; i<mydata.length; i++) {
var row = mydata[i];
var r = 0;
var d = new Object();
for (var c in my_colheader) {
d[c] = {text:row[r++]};
}
my_data.push(d);
}
window.application.main = function()
{
var d = this.getClientWindow().getClientDocument();
var lv = new QxListView(my_data, my_colheader);
lv.setWidth(320)
lv.setHeight(200)
lv.getPane().getManager().addEventListener("changeSelection",
function(e) {
var selItems = e.getData()
for (var i=0; i<selItems.length; i++) {
var item = selItems[i]
var msg = new Array ()
for (var c in item) {
if (c.substr(0,PREFIX.length) == PREFIX) {
var column = c.substr(PREFIX.length)
var val = item[c].text
msg.push (column+":"+val)
}
}
alert("You selected -> "+msg.join(","))
}
});
d.add(lv)
}
</script>
</body>
</html>
Quoting Jim Hunter <[EMAIL PROTECTED]>:
Thanks for the info but it doesn't solve my issue. I will never know what is
in the data. It is an ever changing structure and I have to access the
information on the fly. I can never reference the column by name as your
example shows. I will work more with it before I have to write this part of
the code.
Thanks,
Jim
On 5/2/06, Chris Esler <[EMAIL PROTECTED]> wrote:
to see how the object is formulated, use JSON to convert the object to a
string then output to an alert() so you can see how it is laid out. See
attached file for JSON.
that way you can see the indices you need to access.
/*
Lets assume your list is set up like this:
*/
myList_ld = [];
omyList_lc =
{
id : { label : "Id", width : "10%", type : "text", sortable :
true, sortProp : "text", align : "center" },
name : { label : "Name", width : "50%", type : "text", sortable :
true, sortProp : "text", align : "left" },
date : { label : "Date", width : "40%", type : "text", sortable :
true, sortProp : "text", align : "left" }
};
myList_lv = new QxListView(myList_ld, myList_lc);
myList_lv.setBorder(QxBorderObject.presets.shadow);
myList_lv.setBackgroundColor("white");
myList_lv.setWidth(350);
myList_lv.setHeight(200);
myList_lv.setLocation(20, 38);
myList_lv.getPane().getManager().setMultiSelection(false);
/*
then to see how the items structure is setup, run it through JSON
*/
var myList_sel = myList_lv.getPane().getSelectedItem();
alert("ID :: "+JSON.stringify(myList_sel));
/*
this should give you
*/
{"id":{"text":"36"},"name":{"text":"04-25-2006"},"date":{"text":"test"},"_lead":true,"_anchor":true,"_hashCode":1352,"_hash":1352,"_selected":true}
/*
now I know how my object is setup to access the data.
Assuming we want to access the "id" field, I can can change the alert() to
the following
*/
alert("ID :: "+myList_sel['id'].text);
/*
this should give you the id column data of your data set since I know what
the indice is now
*/
Hope this helps...
--
Best regards,
Chris Esler
www.chrisesler.com
On 4/23/06, Jim Hunter <[EMAIL PROTECTED]> wrote:
Thanks for the info. When I first wrote this reply I had not yet figured
out your other post with regards to adding my own index value to the row. I
was trying to determine how to get that value back out of the row and was
failing. But this is what I learned: I had to access the index
property like
this:
x=this.getPane().getManager().getSelectedItems();
row=x[0].__index.text;
but as you can see, I needed to know the name of the row property in
order to reference it. I tried to do something like x[0][2] to access the
third column data but it didn't work. Lets say I simply need to iterate
through all the columns/properties of the selected rows to get data to pass
to another function, what is the easiest way to do that? Right now I only
had a need to have an index value and I have that solved with your
assistance. Now I am going to tackle the pre-selected flag and then a row
color flag which I suspect will both be handled in the same way.
Thanks again,
Jim
On 4/23/06, Benjamin Reitzammer <[EMAIL PROTECTED]> wrote:
>
>
>
> Jim Hunter wrote:
> > This information is nice but it still doesn't tell us what we can DO
> > with getSelectedItems(). In one of the demo's I think I saw that you
> can
> > do a getSelectedItems().getData(), but no information on what you
> can DO
> > with the returned data. I would love to see some code snippet
> showing
> > how to access the second fields data of the second row selected
> assuming
> > that 3 rows were selected. A simple alert would do. All of my
> ListViews
> > are dynamically created at run time and I have no idea at design
> time
> > what fields are going to be in a ListView so I need to be able to
> access
> > the information generically. I tried to do something like
> > getSelectedItems().getData()[0], trying to reference the first row
> > selected but got a JavaScript error.
>
> You got an error, because it must be getSelectedItems()[0] .... the
> getData() method only works on the QxListView instance ... or on your
> QxData event that you receive when you listen on the "changeSelected"
> event of the listviewpane's selection manager ... depending on how
> you
> get to the data of the selected items ... maybe you want to add the
> following snippet to your app and see what happens (may contain syntax
> errors, sorry for being too lazy to test it)
>
> listView.getPane().getManager()
> .addEventListener("changeSelection",
> function(e) {alert( e.getData().length +" "+ e.getData()[0])
> }
> );
>
>
> > There really is no information in
> > the demos that tell you how to manipulate the raw data. The examples
> > that move data from one grid to another never drill down into the
> data,
> > the leave it as a whole entity. So far I have read as many posts as
> I
> > can and looked at the demos but I see no information that is
> relevant to
> > what I need to do. Someone out there has had to have done this
> before
> > and can show others how it's done.
>
> Ok, now because I can't keep my mouth shut ... tell me an exact
> example
> what you want to do (e.g. change one column of data at runtime,
> manipulate just the selected rows of a list), so I get an idea what
> you
> are looking for, and I'll try to do a short writeup with an extended
> example.
>
> Cheers
>
> Benjamin
>
>
> -------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services,
> security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache
> Geronimo
>
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Qooxdoo-devel mailing list
> Qooxdoo-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Qooxdoo-devel mailing list
Qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel