PDA

View Full Version : how to convert HTMLElement or get data



dn2965
19 Jan 2007, 7:46 AM
sorry
i already reading doc defaultDataModel、xmlDataModel and more... please help me




var grid
var XmlExample = {
init : function(){
var schema = {
tagName: 'Item',
id: 'ASIN',
fields: ['name', 'info']
};
dataModel = new YAHOO.ext.grid.XMLDataModel(schema);

// the DefaultColumnModel expects this blob to define columns. It can be extended to provide
// custom or reusable ColumnModels
var colModel = new YAHOO.ext.grid.DefaultColumnModel([
{header: "name", width: 100, sortable: true},
{header: "info", width: 60, sortable: true}
]);

// create the Grid
grid= new YAHOO.ext.grid.Grid('example-grid', dataModel, colModel);
grid.autoWidth = true;
grid.autoHeight = true;
grid.render();

dataModel.load('sheldon.xml');
grid.on("rowclick",myf);
//rowclick : (Grid this, Number rowIndex, YAHOO.ext.EventObject e)


function myf(g,r,e){
//alert(r) //OK
var gHtm=g.getRow(0);
alert(gHtm==null);//return false

}

}
}
YAHOO.ext.EventManager.onDocumentReady(XmlExample.init, XmlExample, true);



xml

<?xml version="1.0" encoding="UTF-8"?>
<result>

<Items>

<Item>
<name>TESTDATA</name>
<info>test test</info>
</Item>

</Items>
</result>

on my Function myf
i try to call the grid's method --> getRow(int) i know it will return a HTMLElement

i am try to get the row's data
but i don't know (i read DOC already!)how to get data by HTMLElement

i want to get the data--> TESTDATA
could anybody tell me how to convert or easy access it

Animal
19 Jan 2007, 8:04 AM
You ask the DataModel for the data, not the Grid!

tryanDLS
19 Jan 2007, 8:04 AM
The grid is the HTML representation of the data, the DataModel is the underlying data. So
1) You need to look at DataModel.getRow
2) Rather than monitor grid.click, you should probably monitor SelectionModel.rowSelect -that way you know you have a selected row (maybe more than 1)

dn2965
19 Jan 2007, 9:10 AM
i am reallyreally thanks you help(two)
its a small thing but
i am very happy.i did i success

my code on botton

function myf(g,r,e){
//alert(r)
var gHtm=g.getRow(0);
alert(gHtm==null);
//alert(gHtm.Text);
var mydm=g.getDataModel();
//alert();
var arr2=new Array();
arr2[0]=r
arr2[1]=0


//it is mean(startROW , endROW)
var arr=mydm.getRows(arr2)[0][1];//(resultROWS_index,whichColumn)
alert(arr)

dn2965
19 Jan 2007, 9:13 AM
but what is the HTMLElement
where do i use it
do i get data from HTMLElement too?