DataDriver.htmltable

class webix.DataDriver.htmltable()

Datadriver.htmltable mixin

References

helpers
assert(), extend(), toNode().

External references

Official documentation page.

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
webix.DataDriver.htmltable={

    //convert json string to json object if necessary
    toObject:function(data){
        data = webix.toNode(data);
        webix.assert(data, "table is not found");
        webix.assert(data.tagName.toLowerCase() === 'table', "Incorrect table object");

        var tr = data.rows;
        webix.html.remove(data);
        return tr;
    },
    //get array of records
    getRecords:function(data){
        var new_data = [];
        //skip header rows if necessary
        var i = (data[0] && data[0]._webix_skip)?1:0;

        for (; i < data.length; i++)
            new_data.push(data[i]);
        return new_data;
    },
    //get hash of properties for single record
    getDetails:function(data){
        var td = data.getElementsByTagName('td');
        data = {};
        //get hash of properties for single record, data named as "data{index}"
        for (var i=0; i < td.length; i++) {
            data['data' + i] = td[i].innerHTML;
        }
        return data;
    },
    //get count of data and position at which new data need to be inserted
    getInfo:function(data){
        // dyn loading is not supported for htmltable
        return {
            size:0,
            from:0
        };
    },
    getOptions:function(){},

    /*! gets header from first table row
     **/
    getConfig: function(data) {
        var columns = [];
        var td = data[0].getElementsByTagName('th');
        if (td.length) data[0]._webix_skip = true;
        for (var i = 0; i < td.length; i++) {
            var col = {
                id: 'data' + i,
                header: this._de_json(td[i].innerHTML)
            };
            var attrs = this._get_attrs(td[i]);
            col = webix.extend(col, attrs);
            columns.push(col);
        }
        return columns;
    },

    _de_json:function(str){
        var pos = str.indexOf("json://");

        if (pos != -1)
            str = JSON.parse(str.substr(pos+7));
        return str;
    },

    /*! gets hash of html-element attributes
     **/
    _get_attrs: function(el) {
        var attr = el.attributes;
        var hash = {};
        for (var i = 0; i < attr.length; i++) {
            hash[attr[i].nodeName] = this._de_json(attr[i].nodeValue);
        }
        hash.width = parseInt(hash.width, 10);
        return hash;
    }
};