Treenode to GridView - extjs4

ExtJS4
I'm trying to move a treenode to gridpanel. I want its associated data to be inserted here. But whenever I move the treenode, it creates an empty row at that position.
I've created the tree as:
var treeData = {
text: 'Business Processes',
children:[
{text: 'Process7', lob: 'Lob7', leaf:true},
{text: 'Process8', lob: 'Lob8', leaf:true},
{text: 'Process9', lob: 'Lob9', leaf:true},
{text: 'Process10', lob: 'Lob10', leaf:true},
{text: 'Process11', lob: 'Lob11', leaf:true},
{text: 'Process12', lob: 'Lob12', leaf:true}
]
};
bpTreeStore = Ext.create('Ext.data.TreeStore',{});
bpTreeStore.setRootNode(treeData);
new Ext.TreePanel({
id:'businessProcessTree',
store : bpTreeStore,
viewConfig: {
plugins:{
ptype: 'treeviewdragdrop',
dropGroup: 'dragGroup',
dragGroup: 'dragGroup',
dragText: 'Place the node to grid'
}
}
});
And the grid as
Ext.define('BusinessProcessStoreModel',{
extend:'Ext.data.Model',
fields: [
{ name:'businessProcessName', type:'string' },
{ name:'businessProcessLob', type:'string' }
]
});
bpMappingStore = Ext.create('Ext.data.ArrayStore', {
model:'BusinessProcessStoreModel',
data:[
['Process1', 'Lob1'],
['Process2', 'Lob2'],
['Process3', 'Lob3']
]
});
var bpMappingGrid = Ext.create('Ext.grid.Panel',{
id:'bpGridPanel',
region:'center',
frame:true,
layout:'fit',
height:300,
columns:[
{ header:'Process Name', dataIndex:'businessProcessName' },
{ header:'Process Lob', dataIndex:'businessProcessLob' }
],
store:bpMappingStore,
viewConfig: {
plugins:{
ptype: 'gridviewdragdrop',
dropGroup: 'dragGroup',
dragGroup: 'dragGroup',
dragText: 'Place the node to grid'
},
listeners: {
drop: function(node, data, overModel, dropPosition)
{
var position = (dropPosition=='after'?overModel.index + 1: overModel.index -1);
Ext.getCmp('bpGridPanel').store.insert(position, [[data.records[0].data.text, 'LOB']]);
//data.records[0].data.lob is undefined don't know why
}
}
}
});
Please tell me how I refer to the 'text' and 'lob' of the treenode to be inserted into the two columns of the gridpanel.
Here I've created my own

I solved the problem. Make sure that the Treenode being dragged must contain the attributes in the model which the grid is using.
Here, treedata can be defined as
var treeData = {
text: 'Business Processes',
children:[
{text: 'Process7', businessProcessName: 'Process7', businessProcessLob: 'Lob7', leaf:true},
{text: 'Process8', businessProcessName: 'Process8', businessProcessLob: 'Lob8', leaf:true},
{text: 'Process9', businessProcessName: 'Process9', businessProcessLob: 'Lob9', leaf:true},
{text: 'Process10',businessProcessName: 'Process10', businessProcessLob: 'Lob10', leaf:true},
{text: 'Process11', businessProcessName: 'Process11', businessProcessLob: 'Lob11', leaf:true},
{text: 'Process12', businessProcessName: 'Process12', businessProcessLob: 'Lob12', leaf:true}
]
};
this.bpTreeStore = Ext.create('Ext.data.TreeStore',{root: this.treeData});
But when we assign this treedata object to the treestore. It removes the new attributes (businessProcessName and businessProcessLob).
So to add them, a loop can be run.
for(var index in treeData.children)
{
this.bpTreeStore.tree.root.childNodes[index].data.businessProcessName = treeData.children[index].businessProcessName;
this.bpTreeStore.tree.root.childNodes[index].data.businessProcessLob = treeData.children[index].businessProcessLob;
}
After this, dragging works fine :)

Related

Display Selected values in v-select multiple

I am new in vue js. Using vue2, I have a v-select implemented on my site now, I want to select multiple values and save and show them while editing. But I can't show multiple values properly using :reduce
Here is my code:
<v-select name="allowed_extensions"
:reduce="allowed_extensions => allowed_extensions.value"
multiple
:closeOnSelect="false"
v-model="form.allowed_extensions"
:options="file_options"
v-validate="'required'" > </v-select>
In js:
data () {
return {
isDisabled: false, //Submit Button
form: {
maximum_file_size: '',
allowed_extensions: ''
},
be_errors: {},
// Options
file_options: [
{ label: 'doc', value: 'doc' },
{ label: 'docx', value: 'docx' },
{ label: 'pdf', value: 'pdf' },
{ label: 'txt', value: 'txt' },
{ label: 'gif', value: 'gif' },
{ label: 'png', value: 'png' },
{ label: 'jpg', value: 'jpg' },
{ label: 'jpeg', value: 'jpeg' }
]
}
}
IN Mysql DB, sample data saved as : ["doc","txt"]
But when I want to display them in edit, it showing wrongly in a single tag.
How can I solve this

setting dgrid allowSelectAll to true is not working

I have an empty grid, with the columns defined as below:
var json = { };
json.col1 = { label: 'Select', selector: 'checkbox' };
json.bndryName = "Boundary Name";
return json;
The boundary grid is initialized as below and the data/collection is loaded on a button click,and when I set allowSelectAll:true, I donot see the the header column rendered with a checkbox to select All. Please advise.
this._bndryGrid = new (declare([OnDemandGrid, Selection,Selector,ColumnResizer]))({
selectionMode: "multiple",
columns: columns,
class:'grid',
loadingMessage: "Loading data...",
noDataMessage: "No results found."
}, this.ap);
I'm not sure you've provided enough to go on here (and your grid doesn't even include allowSelectAll: true), but here is an example that works:
require({
packages: [
{
name: 'dgrid',
location: '//cdn.rawgit.com/SitePen/dgrid/v1.0.0'
},
{
name: 'dstore',
location: '//cdn.rawgit.com/SitePen/dstore/v1.1.1'
}
]
}, [
'dojo/_base/declare',
'dgrid/OnDemandGrid',
'dgrid/Selection',
'dgrid/Selector',
'dstore/Memory',
'dojo/domReady!'
], function(declare, OnDemandGrid, Selection, Selector, Memory) {
var data = [
{ id: 1, name: 'Peter' },
{ id: 2, name: 'Paul' },
{ id: 3, name: 'Mary' }
];
var store = new Memory({ data: data });
var options = {
allowSelectAll: true,
collection: store,
columns: [
{ field: 'id', label: '', selector: 'checkbox' },
{ field: 'name', label: 'Name' }
]
};
new (declare([ OnDemandGrid, Selection, Selector ]))(options, 'gridcontainer');
});

Pick event not triggered for select field picker,while importing sencha-touch/base scss

I am having one select field and want to handle select field picker events manually. Following code for selectfield :
{
xtype: 'selectfield',
label: 'Choose one',
name:'abcd',
usePicker:true,
options: [
{text: 'First Option', value: 'first'},
{text: 'Second Option', value: 'second'},
{text: 'Third Option', value: 'third'}
],
defaultPhonePickerConfig: {
hideOnMaskTap: true,
listeners: {
change: function(ths, val) {
console.log('change event called');
},
pick: function(ths, The, slot) {
console.log('pick event called');
PICKER_CONFIG = null;
if (PICKER_CONFIG != true) {
if (The[slot.getName()] != undefined && The[slot.getName()] != null && The[slot.getName()] != "") {
// Ext.getCmp('contractList').setValue(The[slot.getName()]);
ths.fireEvent('change', ths, The);
ths.hide();
}
}
},
cancel: function() {
console.log('cancel called');
PICKER_CONFIG = true;
},
show:function(){
console.log('show called');
}
}
},
pick is not getting called because i am using base css .
Here is my app.scss
#import 'sencha-touch/base';
But its working if i am using sencha-touch default and default/all css
like:
#import 'sencha-touch/default';
#import 'sencha-touch/default/all;
but, i don't want to use it
Is there any way to get that pick by using sencha-touch/base css.
hmm...
Can you tell me from where you get "pick" event ?
And what it supposed to do ?
I'm guessing that its doing the same thing as "change".
And how do you know its because you are using base css ?
from what I read the base css is sencha will be using bare minimum styling for components to work and the rest will be up to user. so there should be no effect on event components behaviour.
This is what i wrote to set Picker in SelectField:
{
xtype: 'selectfield',
usePicker: true,
displayField: 'text',
valueField: 'value',
options: [
{ text: 'Choose Dosage', value: 'default' },
],
defaultPhonePickerConfig : {
listeners: {
change: function(thePicker, newValue, oldValue) {
//check if custom variable has been set to false
if (newValue.slotsNumeric != null && newValue.slotsDecimal != null) {
var total = newValue.slotsNumeric + newValue.slotsDecimal;
// set the select field to show the correct selected value!!
var DecimalPicker = Ext.ComponentQuery.query('selectfield')[0];
DecimalPicker.setOptions({
text: total,
value: total
});
}
},
},
useTitles: true,
hideOnMaskTap: true,
slots: [
{
name : 'slotsNumeric',
title : 'Numeric',
align: 'center',
data : [
{text: '0', value: 0},
{text: '1', value: 1},
{text: '2', value: 2},
{text: '3', value: 3},
{text: '4', value: 4},
{text: '5', value: 5},
{text: '6', value: 6},
{text: '7', value: 7},
{text: '8', value: 8},
{text: '9', value: 9},
]
},
{
name : 'slotsDecimal',
title : 'Decimal',
align: 'center',
data : [
{text: '.0', value: .0},
{text: '.1', value: .1},
{text: '.2', value: .2},
{text: '.3', value: .3},
{text: '.4', value: .4},
{text: '.5', value: .5},
{text: '.6', value: .6},
{text: '.7', value: .7},
{text: '.8', value: .8},
{text: '.9', value: .9},
]
}
]
}
}

Static grid with dynamic data on button click in extjs4

I'm trying to display different data (from different store and model) deponding on button click but failing at some point ( to be frank, I'm not sure how to use the reconfigure function). Below is my code:
Components and button click function:
Ext.define('MyApp.view.MyPanel', {
extend: 'Ext.panel.Panel',
height: 328,
width: 478,
title: 'My Panel',
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'button',
text: 'Button1'
},
{
xtype: 'button',
text: 'Button2',
listeners: {
click: {
fn: me.onButtonClick,
scope: me
}
}
},
{
xtype: 'button',
text: 'Button3'
},
{
xtype: 'gridpanel',
id: 'myGrid',
title: 'My Grid Panel',
store: 'Button1Store',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'Name',
text: 'Name'
},
{
xtype: 'gridcolumn',
dataIndex: 'Email',
text: 'Email'
}
]
}
]
});
me.callParent(arguments);
},
onButtonClick: function(button, e, eOpts) {
//alert("button 2");
var gridVar = Ext.getCmp('myGrid');
var newStore = Ext.getCmp('MyStore2');
//alert( gridVar.columns[0].dataIndex);
//gridVar.bindStore(newStore);
gridVar.reconfigure(newStore, gridVar.columns);
}
});
Store1 and Model 1:
Ext.define('MyApp.store.Button1Store', {
extend: 'Ext.data.Store',
requires: [
'MyApp.model.Button1Model'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
model: 'MyApp.model.Button1Model',
storeId: 'MyStore1',
data: [
{
Name: '1',
Email: 'test1'
},
{
Name: '2',
Email: 'test2'
},
]
}, cfg)]);
}
});
Ext.define('MyApp.model.Button1Model', {
extend: 'Ext.data.Model',
idProperty: 'Button1Model',
fields: [
{
name: 'Name'
},
{
name: 'Email'
}
]
});
Store 2 and Model 2:
Ext.define('MyApp.store.Button2Store', {
extend: 'Ext.data.Store',
requires: [
'MyApp.model.Button2Model'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
model: 'MyApp.model.Button2Model',
storeId: 'MyStore2',
data: [
{
Name: '3',
Email: 'test3'
},
{
Name: '4',
Email: 'test4'
}
]
}, cfg)]);
}
});
Ext.define('MyApp.model.Button2Model', {
extend: 'Ext.data.Model',
fields: [
{
name: 'Name'
},
{
name: 'Email'
}
]
});
When I try this, the title and data in the grid dissappears. I tried the gridVar.bindStore(newStore); but it throwed an error stating that data is null or undefined. Pls help...
If you are using same grid for all actions then change the store's proxy URL for various actions and populate the data to grid by using load() method !!

SenchaTouch Picker implementation?

i'm using SenchaTouch and would like to use their Picker for a UI component. I have this code:
var datePicker = new Ext.Picker({
slots: [
{
name : 'limit_speed',
useTitles: true,
title: 'Terminals',
data : [
{text: 'Terminalq 1', value: 1},
{text: 'Terminal 2', value: 2},
{text: 'Terminal 3', value: 3},
{text: 'Terminal 4', value: 4}
]
}
]
});
Does anyone know how to get an event handler to work on the doneButton??
Adding a function to the change event.
datePicker.on('change', function(){
// do some stuff
});
or
var datePicker = new Ext.Picker({
slots: [
{
name : 'limit_speed',
useTitles: true,
title: 'Terminals',
data : [
{text: 'Terminalq 1', value: 1},
{text: 'Terminal 2', value: 2},
{text: 'Terminal 3', value: 3},
{text: 'Terminal 4', value: 4}
]
}
],
listeners: {
change: {
element: 'el', //bind to the underlying el property on the panel
fn: function(){ console.log('click el'); }
}
}
});
you could also add it to the 'hide' event, depends if you care about the value or not.
if u want to take value of selected field u can use this code.
listeners: {
change: function(picker,button) {
selectedValue = picker.getValue()['limit_speed'];
console.log(selectedValue);
}
}
You can get the selected value of dynamically created datepicker
listeners: {
change: function(picker,selectedValue) {
console.log(selectedValue);
}
}