extjs 4 - Unable to expand a dynamically generated tree - extjs4

I have a requirement to create a tree grid which has unknown number of columns and data which gets rendered on click on a button. I have following code for the same.
//Model
Ext.define('SM.model.DynamicTreeModel', {
extend: 'Ext.data.Model'
});
//Store
Ext.define('SM.store.DynamicTreeStore',{
extend:'Ext.data.TreeStore',
model:'SM.DynamicTreeModel',
root: {
expanded: true
},
proxy: {
type: 'ajax',
url: 'TGData1.json',
reader: {
type: 'json',
root: 'children'
}
},
autoLoad: true
});
Ext.define('SM.view.compareScenario.DynamicTree', {
extend: 'Ext.tree.Panel',
alias: 'widget.DynamicTree',
frame: true,
columnLines: true,
autoLoad: false,
initComponent: function(){
var config = {
columns: [],
rowNumberer: false
};
Ext.apply(this, config);
Ext.apply(this.initialConfig, config);
this.callParent(arguments);
},
storeLoad: function(){
var columns = [];
Ext.each(this.store.proxy.reader.jsonData.columns, function(column){
columns.push(column);
});
this.reconfigure(this.store, columns);
this.store.getRootNode(this.store.getRootNode);
},
onRender: function(ct, position){
SM.view.compareScenario.DynamicTree.superclass.onRender.call(this, ct, position);
this.store.load({
scope: this,
callback: function(records, operation, success) {
this.storeLoad();
}
});
}
});
var influencesTree = {
xtype: 'DynamicTree',
id: 'influencesTree',
pading: '5',
region: 'south',
height: '70%',
collapsible: true,
rootVisible: false,
store: 'DynamicTreeStore'
};
The json file is as follows:
{
"metaData": {
"fields": [
{"name":"0", "type":"string"},
{"name":"1", "type":"string"},
{"name":"2", "type":"string"}
]
},
"columns" : [
{
"xtype":"treecolumn", //this is so we know which column will show the tree
"text":"Override Type",
"flex":"2",
"sortable":"true",
"dataIndex":"0"
},
{
"text":"Scenario 1",
"dataIndex":"1"
},
{
"text":"Copied Scenario",
"dataIndex":"2"
}
]
,
"text": ".",
"children": [{
"0":"CFO",
"1":"15",
"2":"16",
"children":[{
"0":"AW",
"1": "5",
"2": "5",
"leaf": "true",
},
{
"0":"AV",
"1":"10",
"2":"11",
"leaf": "true",
}
]
}
]
}
The tree renders, but the child nodes cannot be expanded as the + icon is not shown. Instead of + icon, a checkbox is rendered.
Any help/suggestions for the same will be highly appreciated.
Thanks,
Shalini

Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.dd.*']);
Ext.onReady(function () {
var myData = [{
name: "Rec 0",
type: "0"
}, {
name: "Rec 1",
type: "1"
}, {
name: "Rec 2",
type: "2"
}, {
name: "Rec 3",
type: "3"
}, {
name: "Rec 4",
type: "4"
}, {
name: "Rec 5",
type: "5"
}, {
name: "Rec 6",
type: "6"
}, {
name: "Rec 7",
type: "7"
}, {
name: "Rec 8",
type: "8"
}, {
name: "Rec 9",
type: "9"
}];
// create the data store
var firstGridStore = Ext.create('Ext.data.Store', {
model: 'Apps.demo.model.Resource',
autoLoad: true,
proxy: {
type: 'ajax',
url: '/echo/json/',
actionMethods: {
read: 'POST'
},
extraParams: {
json: Ext.JSON.encode(myData)
},
delay: 0
}
});
// Column Model shortcut array
var columns = [{
text: "Name",
flex: 1,
sortable: true,
dataIndex: 'name'
}, {
text: "Type",
width: 70,
sortable: true,
dataIndex: 'type'
}];
// declare the source Grid
var firstGrid = Ext.create('Ext.grid.Panel', {
viewConfig: {
plugins: {
ptype: 'gridviewdragdrop',
ddGroup: 'selDD'
},
listeners: {
drop: function (node, data, dropRec, dropPosition) {
}
}
},
store: firstGridStore,
columns: columns,
stripeRows: true,
title: 'First Grid',
margins: '0 2 0 0'
});
// create the destination Grid
var secondTree = Ext.create('Apps.demo.view.TreeGrid', {
viewConfig: {
plugins: {
ptype: 'treeviewdragdrop',
ddGroup: 'selDD'
},
listeners: {
beforedrop: function (node, data) {
data.records[0].set('leaf', false);
data.records[0].set('checked', null);
},
drop: function (node, data, dropRec, dropPosition) {
firstGrid.store.remove(data.records[0]);
}
}
}
});
var displayPanel = Ext.create('Ext.Panel', {
width: 650,
height: 300,
layout: {
type: 'hbox',
align: 'stretch',
padding: 5
},
renderTo: 'panel',
defaults: {
flex: 1
}, //auto stretch
items: [
firstGrid,
secondTree],
dockedItems: {
xtype: 'toolbar',
dock: 'bottom',
items: ['->', // Fill
{
text: 'Reset both components',
handler: function () {
firstGridStore.loadData(myData);
secondTreeStore.removeAll();
}
}]
}
});
});
var response = Ext.JSON.encode({
"children": [{
"itemId": 171,
"type": "comedy",
"name": "All the way",
"children": [{
"leaf": true,
"itemId": 171,
"type": "actor",
"name": "Rowan Atkinson"
}],
}, {
"itemId": 11,
"type": "fantasy",
"name": "I love You",
"children": [{
"itemId": 11,
"leaf": true,
"type": "actor",
"name": "Rajan",
}]
}, {
"itemId": 173,
"type": "Action",
"name": "Fast and Furious",
"children": [{
"itemId": 174,
"type": "actor",
"name": "Dwayne Johnson",
"children": [{
"leaf": true,
"itemId": 175,
"type": "wrestler",
"name": "The Rock"
}]
}]
}]
});
Ext.define('Apps.demo.model.Resource', {
extend: 'Ext.data.Model',
fields: [{
name: "name",
type: "string"
}, {
name: "type",
type: "string"
}]
});
Ext.define('Apps.demo.view.TreeGrid', {
extend: 'Ext.tree.Panel',
title: 'Demo',
height: 300,
rootVisible: true,
singleExpand: true,
initComponent: function () {
Ext.apply(this, {
store: new Ext.data.TreeStore({
model: 'Apps.demo.model.Resource',
"root": {
"name": "",
"type": "",
"expanded": "true"
},
proxy: {
type: 'ajax',
url: '/echo/json/',
actionMethods: {
read: 'POST'
},
extraParams: {
json: response
},
delay: 0
}
}),
listeners: {
'beforeiteminsert' : function(obj, node) {
console.log(node);
}
},
columns: [{
xtype: 'treecolumn',
text: 'Name',
dataIndex: 'name',
width: 200
}, {
text: 'Type',
dataIndex: 'type'
}]
});
this.callParent();
}
});
var grid = Ext.create('Apps.demo.view.TreeGrid');
Please check this code .It might not give u the proper answer but will surely give u the hint how to achieve the output.

Related

How to display list of data in a column in iview table

In iview table, my colums:
export default {
data () {
return {
columns5: [
{
title: 'CNAME',
key: 'name',
sortable: true
},
{
title: 'nodes',
key: 'nodes',
},
{
title: 'domains',
key: 'domains',
},
{
title: 'desc',
key: 'desc'
},
{
title: 'duetime',
key: 'duetime',
sortable: true
},
{
title: 'ctime',
key: 'ctime',
sortable: true
},
{
title: 'uptime',
key: 'uptime',
sortable: true
},
],
the data:
anames:[
{
"id": 1,
"nodes": [
{
"id": 1,
"main_ip": "10.10.10.10",
"ips": "10.10.10.10\r\n10.10.10.11",
"req_secret": null,
"ctime": "2021-05-17T09:41:53.159131+08:00",
"uptime": "2021-05-17T10:31:47.886033+08:00",
"cname": 1
}
],
"domains": [
{
"id": 1,
"domain_name": "baidu.com",
"ctime": "2021-05-17T16:19:18.097807+08:00",
"uptime": "2021-05-17T16:19:18.097955+08:00",
"cname": 1
}
],
"name": "masdcom",
"desc": "",
"desc_en": null,
"is_active": true,
"duetime": "2021-06-17T19:40:00+08:00",
"ctime": "2021-05-17T09:13:57.019125+08:00",
"uptime": "2021-05-17T19:42:23.025122+08:00",
"user": 2
}
]
You see my nodes and domains,in data anames they are list, not just key-value, how can I display domain's domain_name and node's main_ip?
In there can not use domains.domain_name and nodes.main_ip.
I want nodes display all node's main_ip and domains display all domain's domain_name. what should I do in columns?
domains and nodes is array, you forgot about indexes
domains[0].domain_name and nodes[0].main_ip

how to get scripted dashboard with graphite as data source?

How to get metric from graphite data source?
I've got this script, but it's generate random metric from fake data source.
Image:
Where I can set graphite data source in this script
'use strict';
var window, document, ARGS, $, jQuery, moment, kbn;
var dashboard;
var ARGS;
dashboard = {
rows : [],
schemaVersion: 13,
};
dashboard.title = 'Scripted and templated dash';
dashboard.time = {
from: "now-6h",
to: "now"
};
var rows = 1;
var seriesName = 'argName';
if(!_.isUndefined(ARGS.name)) {
seriesName = ARGS.name;
}
dashboard.rows.push({
title: 'Chart',
height: '300px',
panels: [
{
title: 'Events',
type: 'graphite',
span: 12,
fill: 1,
linewidth: 2,
targets: [
{
'target': 'stats.gauges.WidgetOccurrences.places.300'
}
],
}
]
});
return dashboard;
Try with data source value.
// Intialize a skeleton with nothing but a rows array and service object
dashboard = {
__inputs: [{
'name': "DS",
'label': "datasource_label",
'description': "",
'type': "datasource",
'pluginId': "datasource_plugin_id",
'pluginName': "datasource_plugin_name"
}],
__requires: [{
'type': 'panel',
'id': 'graph',
'name': 'Graph',
'version': ''
},
{
'type': 'datasource',
'id': 'datasource_plugin_id',
'name': 'datasource_plugin_name',
'version': '1.0.0'
}
],
editable: true,
rows: [],
};
dashboard.title = 'Scripted';
dashboard.time = {
from: 'now-36h',
to: 'now'
};
dashboard.rows.push({
title: 'Chart',
height: '300px',
panels: [{
title: 'Variable Importance',
type: 'graph',
span: 12,
fill: 1,
linewidth: 2,
datasource: 'datasource_label',
targets: [{
"target": "target"
}],
seriesOverrides: [],
tooltip: {
shared: true,
sort: 0,
value_type: 'individual'
},
xaxis: {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
yaxes: [{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
]
}]
});
return dashboard;

Complex array at QML

I got in trouble with very simple code:
property var pagesAllModels: {
ru: [
{ title: qsTr("New"), url: "http://bash.im" },
{ title: qsTr("Random"), url: "http://bash.im/random" },
{ title: qsTr("Best"), url: "http://bash.im/best" },
{ title: qsTr("By rating"), url: "http://bash.im/byrating" },
{ title: qsTr("Abyss"), url: "http://bash.im/abyss" },
{ title: qsTr("Abyss top"), url: "http://bash.im/abysstop" },
{ title: qsTr("Abyss best"), url: "http://bash.im/abyssbest" },
],
eng: [
{ title: "Latest", url: "http://bash.org/?latest" },
{ title: "Browse", url: "http://bash.org/?browse" },
{ title: "Random", url: "http://bash.org/?random" },
{ title: "Top", url: "http://bash.org/?top" }
]
}
That code in QML gives me error at line "eng: [" with error "expected lexem ," but in pure javascript everything work fine. What's wrong?
That's because your code is illegal JSON array definition. Web browsers are accepting it because they aren't strict about JS syntax, but QML engine is really strict :
In a key:value pair in associative array, the key must be a string, so it must have quotes around it, else it would be confused with a (non-existing) variable name.
property var pagesAllModels: {
"ru": [
{ "title": qsTr("New"), "url": "http://bash.im" },
{ "title": qsTr("Random"), "url": "http://bash.im/random" },
{ "title": qsTr("Best"), "url": "http://bash.im/best" },
{ "title": qsTr("By rating"), "url": "http://bash.im/byrating" },
{ "title": qsTr("Abyss"), "url": "http://bash.im/abyss" },
{ "title": qsTr("Abyss top"), "url": "http://bash.im/abysstop" },
{ "title": qsTr("Abyss best"), "url": "http://bash.im/abyssbest" }
],
"eng": [
{ "title": "Latest", "url": "http://bash.org/?latest" },
{ "title": "Browse", "url": "http://bash.org/?browse" },
{ "title": "Random", "url": "http://bash.org/?random" },
{ "title": "Top", "url": "http://bash.org/?top" }
]
}
And it works !
Try this
property var pagesAllModels: {
ru: [
{ title: qsTr("New"), url: "http://bash.im" },
{ title: qsTr("Random"), url: "http://bash.im/random" },
{ title: qsTr("Best"), url: "http://bash.im/best" },
{ title: qsTr("By rating"), url: "http://bash.im/byrating" },
{ title: qsTr("Abyss"), url: "http://bash.im/abyss" },
{ title: qsTr("Abyss top"), url: "http://bash.im/abysstop" },
{ title: qsTr("Abyss best"), url: "http://bash.im/abyssbest" }
],
eng: [
{ title: "Latest", url: "http://bash.org/?latest" },
{ title: "Browse", url: "http://bash.org/?browse" },
{ title: "Random", url: "http://bash.org/?random" },
{ title: "Top", url: "http://bash.org/?top" }
]
}
Hope this will resolve your issue
associative arrays separates by semicolon ";"
Try this
property var pagesAllModels: {
ru: [
{ title: qsTr("New"), url: "http://bash.im" },
{ title: qsTr("Random"), url: "http://bash.im/random" },
{ title: qsTr("Best"), url: "http://bash.im/best" },
{ title: qsTr("By rating"), url: "http://bash.im/byrating" },
{ title: qsTr("Abyss"), url: "http://bash.im/abyss" },
{ title: qsTr("Abyss top"), url: "http://bash.im/abysstop" },
{ title: qsTr("Abyss best"), url: "http://bash.im/abyssbest" },
];
eng: [
{ title: "Latest", url: "http://bash.org/?latest" },
{ title: "Browse", url: "http://bash.org/?browse" },
{ title: "Random", url: "http://bash.org/?random" },
{ title: "Top", url: "http://bash.org/?top" }
]
}

using Select2 with Durandal

Hi I am trying to use Select2 (multiselect) with Durandal (http://jsfiddle.net/anasnakawa/6XvqX/381/),
but the popup does not work below is part of my VM and HTML, here I am trying to bind a list of states to an input it should work as an auto complete but there seems to a issue showing the selection popup, can someone please help
define(['durandal/app', 'services/datacontext', 'plugins/router', 'services/bindinghandlers'],
function (app, datacontext, router) {
var withs = ko.observableArray(),
states = [
{ id: "AL", text: "Alabama" },
{ id: "AK", text: "Alaska" },
{ id: "AZ", text: "Arizona" },
{ id: "AR", text: "Arkansas" },
{ id: "CA", text: "California" },
{ id: "CO", text: "Colorado" },
{ id: "CT", text: "Connecticut" },
{ id: "DE", text: "Delaware" },
{ id: "FL", text: "Florida" },
{ id: "GA", text: "Georgia" },
{ id: "HI", text: "Hawaii" },
{ id: "ID", text: "Idaho" },
{ id: "IL", text: "Illinois" },
{ id: "IN", text: "Indiana" },
{ id: "IA", text: "Iowa" },
{ id: "KS", text: "Kansas" },
{ id: "KY", text: "Kentucky" },
{ id: "LA", text: "Louisiana" },
{ id: "ME", text: "Maine" },
{ id: "MD", text: "Maryland" },
{ id: "MA", text: "Massachusetts" },
{ id: "MI", text: "Michigan" },
{ id: "MN", text: "Minnesota" },
{ id: "MS", text: "Mississippi" },
{ id: "MO", text: "Missouri" },
{ id: "MT", text: "Montana" },
{ id: "NE", text: "Nebraska" },
{ id: "NV", text: "Nevada" },
{ id: "NH", text: "New Hampshire" },
{ id: "NJ", text: "New Jersey" },
{ id: "NM", text: "New Mexico" },
{ id: "NY", text: "New York" },
{ id: "NC", text: "North Carolina" },
{ id: "ND", text: "North Dakota" },
{ id: "OH", text: "Ohio" },
{ id: "OK", text: "Oklahoma" },
{ id: "OR", text: "Oregon" },
{ id: "PA", text: "Pennsylvania" },
{ id: "RI", text: "Rhode Island" },
{ id: "SC", text: "South Carolina" },
{ id: "SD", text: "South Dakota" },
{ id: "TN", text: "Tennessee" },
{ id: "TX", text: "Texas" },
{ id: "UT", text: "Utah" },
{ id: "VT", text: "Vermont" },
{ id: "VA", text: "Virginia" },
{ id: "WA", text: "Washington" },
{ id: "WV", text: "West Virginia" },
{ id: "WI", text: "Wisconsin" },
{ id: "WY", text: "Wyoming" }
];
var vm = {
withs: withs,
states: states,
};
return vm;
});
<select multiple="true" data-bind="options: states, optionsValue: 'id', optionsText: 'text', selectedOptions: withs, select2: {}" style="width: 300px"></select>
Register select2 in the Require.js configuration inside main.js:
requirejs.config({
paths: {
'select2': 'path/to/select2'
}
});
Define it in your view model:
define(['select2'], function (select2) {
// ...
});
Don't forget to declare it. You'll have to use the attached callback:
var vm = {
withs: withs,
states: states,
attached: function() {
$('select').select2();
}
};

NestedList in container not showing anything with sencha touch 2.2.1

Below is my model,just a config of fields:
Ext.define('Zjsy.model.TasksToDoModel', {
extend : 'Ext.data.Model',
xtype : 'TasksToDoModel',
config : {
fields : ['text']
}
});
Below is my store,i create data first and make it inline data of the store which i will choose proxy instead:
var data = {
text: 'Groceries',
items: [{
text: 'Drinks',
items: [{
text: 'Water',
items: [{
text: 'Sparkling',
leaf: true
}, {
text: 'Still',
leaf: true
}]
}, {
text: 'Coffee',
leaf: true
}, {
text: 'Espresso',
leaf: true
}, {
text: 'Redbull',
leaf: true
}, {
text: 'Coke',
leaf: true
}, {
text: 'Diet Coke',
leaf: true
}]
}, {
text: 'Fruit',
items: [{
text: 'Bananas',
leaf: true
}, {
text: 'Lemon',
leaf: true
}]
}, {
text: 'Snacks',
items: [{
text: 'Nuts',
leaf: true
}, {
text: 'Pretzels',
leaf: true
}, {
text: 'Wasabi Peas',
leaf: true
}]
}]
};
Ext.define('Zjsy.store.TasksToDoStore', {
extend : 'Ext.data.Store',
xtype : 'TasksTodoStore',
requires : ['Zjsy.model.TasksToDoModel'],
config : {
model : 'Zjsy.model.TasksToDoModel',
data : data
}
});
Below is my view,i create it by extending from container:
Ext.define('Zjsy.view.TasksToDoPanel',
{
extend : 'Ext.Container',
id : 'tasksToDoPanel',
requires: [
'Ext.dataview.*',
'Zjsy.store.TasksToDoStore',
'Ext.data.Store'
],
config : {
xtype : 'panel',
layout : 'vbox',
style : 'background:rgb(218,236,245)',
items : [
{
xtype:'Ext.dataview.NestedList',
store : 'Zjsy.store.TasksToDoStore',
displayField: 'text',
flex: 1,
style : 'border:1px solid red;'
}//nested list
]
}//config
});
When i look up in the chrome logs,it saying
"Uncaught Error: [Ext.createByAlias] Cannot create an instance of unrecognized alias: widget.Ext.dataview.NestedList sencha-touch-all-debug.js:6630"
Can anybody help me ?
Ext.dataview.NestedList is a class name not xtype, so change that in to nestedlist
Remove the xtype from the store and give it storeId : 'TasksTodoStore' inside store config
And you Json is invalid
Model
Ext.define('SF.model.TasksToDoModel', {
extend : 'Ext.data.Model',
config : {
fields : [{
name : 'text',
type : 'string'
}]
}
});
Store
var data = {
"text": "Groceries",
"items": [{
"text": "Drink",
"items": [{
"text": "Water",
"items": [{
"text": "Sparkling",
"leaf": "true"
}, {
"text": "Still",
"leaf": true
}]
}, {
"text": "Coffee",
"leaf": true
}, {
"text": "Espresso",
"leaf": true
}, {
"text": "Redbull",
"leaf": true
}, {
"text": "Coke",
"leaf": true
}, {
"text": "Diet Coke",
"leaf": true
}]
}, {
"text": "Fruit",
"items": [{
"text": "Bananas",
"leaf": true
}, {
"text": "Lemon",
"leaf": true
}]
}, {
"text": "Snacks",
"items": [{
"text": "Nuts",
"leaf": true
}, {
"text": "Pretzels",
"leaf": true
}, {
"text": "Wasabi Peas",
"leaf": true
}]
}]
};
Ext.define('SF.store.TasksToDoStore', {
extend : 'Ext.data.TreeStore',
config : {
model : 'SF.model.TasksToDoModel',
storeId : 'tasksToDoStore',
defaultRootProperty: 'items',
root : data,
autoLoad : false
}
});
View
Ext.define('SF.view.TasksToDoPanel',{
extend : 'Ext.Container',
id : 'tasksToDoPanel',
xtype : 'tasksToDoPanel',
requires: [
'SF.store.TasksToDoStore'
],
config : {
layout : 'fit',
items : [
{
xtype:'nestedlist',
store : 'tasksToDoStore',
title: 'Groceries',
displayField: 'text'
}]
}
});