:: Forum >> Version 2 >>

Loading Multi Header Values From CSV File

Hi All,

I wonder if you may assist me here. I've searched the forum and found a couple of threads that are on my topic, however none of the exiting ones quite fit my requirements.

I am using a CSV file, and would like the first two lines of that file to be used as the two grid headers. (I've set obj.setHeaderCount(2);)

Any assistance would be greatly appreciated.

Current code in use detailed below:

<script type="text/javascript">
    var 
table = new AW.CSV.Table;
    
table.setURL("URLTOCSV");
    
table.request();
    var 
obj = new AW.Grid.Extended;
    
obj.setColumnCount(50);
    
obj.setId("myGrid");
    
obj.setHeaderCount(2);
    
obj.setHeaderHeight(400); // header row-0
    
obj.setHeaderHeight(301); // header row-1
    
obj.setFixedLeft(4);
    
obj.setCellModel(table);
    
document.write(obj);
</
script
Cheers,

Matt
Matt
Tuesday, March 24, 2009
Matt,

unfortunately there is no right event to attach to - it is necessary to modify table.response method to achieve what you want.

var table = new AW.CSV.Table;

    
table.response = function(text){

        
this._rows text.split(/\r*\n/);
        if (!
this._rows[this._rows.length-1]){
            
this._rows.pop();
        }
        
this._data = [];

        if (
this.$owner) {
            
// grid initialization
            
this.$owner.clearScrollModel();
            
this.$owner.clearSelectedModel();
            
this.$owner.clearSortModel();
            
this.$owner.clearRowModel();


            
// copy data to grid headers
            
var imax this.$owner.getColumnCount();
            for (
i=0;i<max;i++){
                
this.$owner.setHeaderText(this.getData(i0), i0); // 1st row
                
this.$owner.setHeaderText(this.getData(i1), i1); // 2nd row
            
}
            
// remove first 2 rows from data arrays
            
this._rows.splice(02);
            
this._data.splice(02);


            
// continue grid initialization
            
this.$owner.setRowCount(this.getCount());
            
this.$owner.refresh();
        }
    };

// then as usual...
 
Alex (ActiveWidgets)
Tuesday, March 24, 2009
Excellent. Thank you very much for your help with this Alex, works perfectly.

Matt
Wednesday, March 25, 2009



This topic is archived.

Back to support forum

Forum search