PDA

View Full Version : Can ExtJS create a datasource from an existing html table?



demotics2002
22 Dec 2010, 11:49 PM
Alright my first post here. I hope I'm at the right section to ask this question.

I understand that I can create a grid with data from a datasource, or can also create a Grid from an existing html table. Something like below...




Ext.onReady(

function(){


var grid1 = new Ext.ux.grid.TableGrid("table0", {

//stripeRows: true, // stripe alternate rows

viewConfig : {
forceFit :true,
getRowClass : function(record, index){
// return a custom css class based on the record or index
// I want to color the row based on some logic here but couldn't get anything from 'record'
}
}





});
grid1.render();
});




<TABLEcellSpacing=0cellPadding=0width="100%"border=1id='table0'>


The problem here is I have no way to retrieve any data from "record" in the getRowClass function. I am thinking if there is a way to create datasource first (from the existing html table) then create a GridPanel using this datasource.


Thanks!!!

Condor
23 Dec 2010, 1:23 AM
The problem here is I have no way to retrieve any data from "record" in the getRowClass function.

Nonsense. You should be able to access the record data just fine!

Animal
23 Dec 2010, 1:48 AM
Anyway, embedding data inside HTML from where it has to be "mined" using a special class using DomQuery is very odd behaviour when you could simply create a Store literal to hold the data, and use that in your GridPanel/DataView/whatever.

demotics2002
23 Dec 2010, 2:10 AM
Nonsense. You should be able to access the record data just fine!

Ok. I shouldn't have asked... coz I was wrong and you are right. Obviously I can get the "record". (record!=null) just returns true. But can you try to get something from "record"? I just can't seem to get anything! Now tell, how you can construct any logic from what the record contains?!!!

Condor
23 Dec 2010, 2:13 AM
By default (if no fields or columns are specified) fields are named tcol-<n>, so you can use:

var value = record.get('tcol-0'); // gets value in first column

demotics2002
23 Dec 2010, 4:57 PM
Great!!! Is it a matter of hacking to know all these? Or it is a pre-requisite to understand everything about html in order to use ExtJs effectively? Anyway, I got it working now. Thanks!!!

Can't find [accept as answer] button.