3.2.0

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(40, 0); // header row-0
    obj.setHeaderHeight(30, 1); // header row-1
    obj.setFixedLeft(4);
    obj.setCellModel(table);
    document.write(obj);
</script>


Cheers,

Matt
Matt
March 24,
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 i, max = this.$owner.getColumnCount();
            for (i=0;i<max;i++){
                this.$owner.setHeaderText(this.getData(i, 0), i, 0); // 1st row
                this.$owner.setHeaderText(this.getData(i, 1), i, 1); // 2nd row
            }
            // remove first 2 rows from data arrays
            this._rows.splice(0, 2);
            this._data.splice(0, 2);


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

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

Matt
March 25,

This topic is archived.

See also:


Back to support forum