TablePaste

class webix.TablePaste()

Tablepaste mixin

References

helpers
extend(), isUndefined().
views
datatable().

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
81
82
83
webix.TablePaste = {
    clipboard_setter:function(value){
        if (value === true || value === 1) this._settings.clipboard = 'block';
        webix.clipbuffer.init();
        this.attachEvent("onSelectChange",this._sel_to_clip);
        // solution for clicks on selected items
        this.attachEvent("onItemClick",function(id,e,node){
            if(document.activeElement && this.$view.contains(document.activeElement)){
                webix.clipbuffer.focus();
                webix.UIManager.setFocus(this);
            }
        });
        this.attachEvent("onPaste", this._clip_to_sel);

        return value;
    },

    _sel_to_clip: function() {
        if (!this.getEditor || !this.getEditor()){
            var data = this._get_sel_text();
            webix.clipbuffer.set(data);
            webix.UIManager.setFocus(this);
        }
    },

    _get_sel_text: function() {
        var data = [];
        this.mapSelection(function(value, row, col, row_ind, col_ind) {
            if (!data[row_ind]) data[row_ind] = [];
            data[row_ind].push(value);
            return value;
        });

        return webix.csv.stringify(data, this._settings.delimiter);
    },

    _clip_to_sel: function(text) {
        if (!webix.isUndefined(this._paste[this._settings.clipboard])) {
            var data = webix.csv.parse(text, this._settings.delimiter);
            this._paste[this._settings.clipboard].call(this, data);
        }
    },

    _paste: {
        block: function(data) {
            var leftTop = this.mapSelection(null);
            if (!leftTop) return;

            // filling cells with data
            this.mapCells(leftTop.row, leftTop.column, data.length, null, function(value, row, col, row_ind, col_ind) {
                if (data[row_ind] && data[row_ind].length>col_ind) {
                    return data[row_ind][col_ind];
                }
                return value;
            });
            this.render();
        },

        selection: function(data) {
            this.mapSelection(function(value, row, col, row_ind, col_ind) {
                if (data[row_ind] && data[row_ind].length>col_ind)
                    return data[row_ind][col_ind];
                return value;
            });
            this.render();
        },

        repeat: function(data) {
            this.mapSelection(function(value, row, col, row_ind, col_ind) {
                row = data[row_ind%data.length];
                value = row[col_ind%row.length];
                return value;
            });
            this.render();
        },

        custom: function(text) {}
    }
};

webix.extend(webix.ui.datatable, webix.TablePaste);
if(!webix.storage)
    webix.storage = {};