-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathxGridResizer.js
58 lines (49 loc) · 1.44 KB
/
xGridResizer.js
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
/**
* Author: Anders Uddenberg <[email protected]>, Peter Bergman <[email protected]>
* Date: 2015-11-26
* Todo: Error checking and handling
*/
define(["qlik", "./properties" ,"text!./btn.css"], function(qlik, props, cssContent) {
var app = qlik.currApp(this);
var sheetId = qlik.navigation.getCurrentSheetId().sheetId;
$( '<style>' ).html( cssContent ).appendTo( 'head' );
function resizeGrid(rows, cols) {
app.getObject(sheetId).then(function(obj) {
obj.applyPatches([{
qOp: 'replace',
qPath: '/columns',
qValue: '"'+cols+'"'
},
{
qPath : '/rows',
qOp : 'replace',
qValue : '"'+rows+'"'
}
],false);
}).then(function() {
app.doSave();
});
} // end resizeGrid()
return {
initialProperties : {
version : 1.0,
alternatives : []
},
definition: ( props )
,
paint : function($element, layout) {
var html = "", ext = this;
html +="<button id=changegrid class=btn>Resize to - > (" + layout.rows + " / " + layout.cols +")</button>";
app.getObject(sheetId).then(function(obj) {
obj.getLayout().then(function(layout) {
$element.find('#size').html(layout.columns);
$element.find('#selector').html(layout.columns);
});
});
$element.html(html).find('#changegrid').on('qv-activate', function(event) {
event.preventDefault();
resizeGrid(layout.rows, layout.cols);
});
}
};
});