\n `).appendTo(e)}}};return t}catch(e){console.error(`materialDesignIcons: error: ${e.message}, stack: ${e.stack}`)}},exportData:function(e,t){try{var a=vis;let l=t[1];var o={input:'",init:function(e,t){$(this).button().click(function(){$(this).val(!0).trigger("change");$(this).data("wdata");var e={};a.config["dialog-edit-text"]&&(e=JSON.parse(a.config["dialog-edit-text"]));var t=ace.edit("dialog-edit-text-textarea"),o=a.activeView;let r="Please select only one Widget to see the Widget data!";if(1===a.activeWidgets.length){let e=[],t=a.findCommonAttributes(o,a.activeWidgets),n={},s="
\n
Property
\n
Description
\n
Type
\n
Values
\n
";for(const a in t)for(const o in t[a])e.push(o);s+="
",Object.keys(n).length>0&&(console.log(n),console.log(s));let c=a.views[o].widgets[a.activeWidgets[0]],d=c.style,u=Object.assign({type:l,width:d.width,height:d.height},c.data);for(var i in u)e.includes(i)&&"exportData"!==i||"type"===i||"width"===i||"height"===i||delete u[i],"select"!==l&&"autocomplete"!==l||"jsonStringObject"!==i||"jsonStringObject"!==u.listDataMethod||u[i].startsWith("{")||u[i].endsWith("}")||(u[i]=JSON.parse(u[i]));r=JSON.stringify(u,null,"\t")}$("#dialog-edit-text").dialog({autoOpen:!0,width:e.width||800,height:e.height||600,modal:!0,resize:function(){t.resize()},open:function(a){$(a.target).parent().find(".ui-dialog-titlebar-close .ui-button-text").html(""),$(this).parent().css({"z-index":1e3}),void 0!==e.top&&(e.top>=0?$(this).parent().css({top:e.top}):$(this).parent().css({top:0})),void 0!==e.left&&(e.left>=0?$(this).parent().css({left:e.left}):$(this).parent().css({left:0})),t.getSession().setMode("ace/mode/html"),t.setOptions({enableBasicAutocompletion:!0,enableLiveAutocompletion:!0}),t.$blockScrolling=1/0,t.getSession().setUseWrapMode(!0),t.setValue(r),t.navigateFileEnd(),t.focus(),t.getSession().on("change",function(){!1})},beforeClose:function(){},buttons:[{text:_("Close"),click:function(){$(this).dialog("close")}}]}).show()})}};return o}catch(e){console.error(`exportData: error: ${e.message}, stack: ${e.stack}`)}}},vis.editMode&&(myMdwMaterialDesignIconsList=vis.binds.materialdesign.materialdesignicons.getList());
\ No newline at end of file
+}},vis.binds.materialdesign.progress={linear:function(e,t){try{let a=$(e),o="materialdesign-vuetify-progress",l="Progress";a.append(`\n
\n `).appendTo(e)}}};return t}catch(e){console.error(`materialDesignIcons: error: ${e.message}, stack: ${e.stack}`)}},exportData:function(e,t){try{var a=vis;let l=t[1];var o={input:'",init:function(e,t){$(this).button().click(function(){$(this).val(!0).trigger("change");$(this).data("wdata");var e={};a.config["dialog-edit-text"]&&(e=JSON.parse(a.config["dialog-edit-text"]));var t=ace.edit("dialog-edit-text-textarea"),o=a.activeView;let r="Please select only one Widget to see the Widget data!";if(1===a.activeWidgets.length){let e=[],t=a.findCommonAttributes(o,a.activeWidgets),n={},s="
\n
Property
\n
Description
\n
Type
\n
Values
\n
";for(const a in t)for(const o in t[a])e.push(o);s+="
",Object.keys(n).length>0&&(console.log(n),console.log(s));let c=a.views[o].widgets[a.activeWidgets[0]],d=c.style,u=Object.assign({type:l,width:d.width,height:d.height},c.data);for(var i in u)e.includes(i)&&"exportData"!==i||"type"===i||"width"===i||"height"===i||delete u[i],"select"!==l&&"autocomplete"!==l||"jsonStringObject"!==i||"jsonStringObject"!==u.listDataMethod||u[i].startsWith("{")||u[i].endsWith("}")||(u[i]=JSON.parse(u[i]));r=JSON.stringify(u,null,"\t")}$("#dialog-edit-text").dialog({autoOpen:!0,width:e.width||800,height:e.height||600,modal:!0,resize:function(){t.resize()},open:function(a){$(a.target).parent().find(".ui-dialog-titlebar-close .ui-button-text").html(""),$(this).parent().css({"z-index":1e3}),void 0!==e.top&&(e.top>=0?$(this).parent().css({top:e.top}):$(this).parent().css({top:0})),void 0!==e.left&&(e.left>=0?$(this).parent().css({left:e.left}):$(this).parent().css({left:0})),t.getSession().setMode("ace/mode/html"),t.setOptions({enableBasicAutocompletion:!0,enableLiveAutocompletion:!0}),t.$blockScrolling=1/0,t.getSession().setUseWrapMode(!0),t.setValue(r),t.navigateFileEnd(),t.focus(),t.getSession().on("change",function(){!1})},beforeClose:function(){},buttons:[{text:_("Close"),click:function(){$(this).dialog("close")}}]}).show()})}};return o}catch(e){console.error(`exportData: error: ${e.message}, stack: ${e.stack}`)}}},vis.editMode&&(myMdwMaterialDesignIconsList=vis.binds.materialdesign.materialdesignicons.getList());
\ No newline at end of file
diff --git a/widgets/materialdesign/js/widgets/materialdesign.table.js b/widgets/materialdesign/js/widgets/materialdesign.table.js
index da02e421..3d4062ce 100644
--- a/widgets/materialdesign/js/widgets/materialdesign.table.js
+++ b/widgets/materialdesign/js/widgets/materialdesign.table.js
@@ -74,6 +74,8 @@ vis.binds.materialdesign.table = {
myMdwHelper.waitForElement($this, `.mdc-data-table`, data.wid, 'Table', function () {
myMdwHelper.waitForRealHeight($this.context, data.wid, 'Table', function () {
let table = $this.find('.mdc-data-table').get(0);
+ let sortByKey = undefined;
+ let sortASC = true;
if (table) {
let height = window.getComputedStyle($this.context, null).height
@@ -97,12 +99,12 @@ vis.binds.materialdesign.table = {
// Content changed
vis.states.bind(data.oid + '.val', function (e, newVal, oldVal) {
- vis.binds.materialdesign.table.getContentElements($this, newVal, data, null, oldVal);
+ vis.binds.materialdesign.table.getContentElements($this, newVal, data, null, oldVal, sortByKey, sortASC);
});
$this.find('.mdc-data-table__header-cell').click(function (obj) {
let colIndex = $(this).attr('colIndex');
- let sortASC = true;
+
let jsonData = [];
if (myMdwHelper.getValueFromData(data.oid, null) !== null && vis.states.attr(data.oid + '.val') !== null) {
@@ -111,7 +113,7 @@ vis.binds.materialdesign.table = {
jsonData = JSON.parse(data.dataJson)
}
- let key = (myMdwHelper.getValueFromData(data.attr('sortKey' + colIndex), null) !== null) ? data.attr('sortKey' + colIndex) : Object.keys(jsonData[0])[colIndex];
+ sortByKey = (myMdwHelper.getValueFromData(data.attr('sortKey' + colIndex), null) !== null) ? data.attr('sortKey' + colIndex) : Object.keys(jsonData[0])[colIndex];
if ($(this).attr('sort')) {
if ($(this).attr('sort') === 'ASC') {
@@ -136,20 +138,7 @@ vis.binds.materialdesign.table = {
}
});
- vis.binds.materialdesign.table.getContentElements($this, null, data, sortByKey(jsonData, key, sortASC)); //TODO: sort key by user defined
-
- function sortByKey(array, key, sortASC) {
- return array.sort(function (a, b) {
- var x = a[key];
- var y = b[key];
-
- if (sortASC) {
- return ((x < y) ? -1 : ((x > y) ? 1 : 0));
- } else {
- return ((x > y) ? -1 : ((x < y) ? 1 : 0));
- }
- });
- }
+ vis.binds.materialdesign.table.getContentElements($this, null, data, vis.binds.materialdesign.table.sortByKey(jsonData, sortByKey, sortASC)); //TODO: sort key by user defined
});
}
});
@@ -158,7 +147,7 @@ vis.binds.materialdesign.table = {
console.error(`[Table - ${data.wid}] handle: error: ${ex.message}, stack: ${ex.stack}`);
}
},
- getContentElements: function ($this, input, data, jsonData = null, oldVal = null) {
+ getContentElements: function ($this, input, data, jsonData = null, oldVal = null, sortByKey = undefined, sortASC = true) {
let tableContent = $this.find('.mdc-data-table__content');
let oldJsonData = null;
let rowsCount = 0;
@@ -166,6 +155,8 @@ vis.binds.materialdesign.table = {
if (jsonData === null) {
jsonData = vis.binds.materialdesign.table.getJsonData(input, data);
+ if (sortByKey) jsonData = vis.binds.materialdesign.table.sortByKey(jsonData, sortByKey, sortASC);
+
rowsCount = jsonData.length - 1;
} else {
rowsCount = jsonData.length - 1;
@@ -174,6 +165,8 @@ vis.binds.materialdesign.table = {
if (oldVal !== null) {
oldJsonData = vis.binds.materialdesign.table.getJsonData(oldVal, data);
+ if (sortByKey) oldJsonData = vis.binds.materialdesign.table.sortByKey(oldJsonData, sortByKey, sortASC);
+
if (rowsCount < oldJsonData.length - 1) {
rowsCount = oldJsonData.length - 1;
}
@@ -234,7 +227,7 @@ vis.binds.materialdesign.table = {
if (existingCell.length === 1) {
if (oldJsonData) {
if (oldJsonData[row] && !myUnderscore.isEqual(Object.values(jsonData[row])[col], Object.values(oldJsonData[row])[col])) {
- // console.log(`notEqual: row: ${row}, col: ${col}`);
+ console.log(`notEqual: row: ${row}, col: ${col}`);
let colElement = getColElement(row, col, Object.values(jsonData[row])[col], textSize, jsonData[row]);
existingCell.replaceWith($(colElement));
@@ -1145,5 +1138,17 @@ vis.binds.materialdesign.table = {
return data;
}
+ },
+ sortByKey: function (array, key, sortASC) {
+ return array.sort(function (a, b) {
+ var x = a[key];
+ var y = b[key];
+
+ if (sortASC) {
+ return ((x < y) ? -1 : ((x > y) ? 1 : 0));
+ } else {
+ return ((x > y) ? -1 : ((x < y) ? 1 : 0));
+ }
+ });
}
};
\ No newline at end of file