Loading the form data using dhtmlxConnector - forms

I built dhtmlxForm with several controls and one of them is dhtmlxGrid inside container.
I need to load the form data using dhtmlxConnector render_array, but don’t know the best way to do it.
var myForm, myGrid;
var formData = [{type: "settings", position: "label-left", inputWidth: 150, labelWidth: 90},{type: "block", name: "buttonBlock", width: 500, list: [{type: "button", name: "btn1", value: "Patrick"},{type: "newcolumn", offsetLeft: 20},{type: "button", name: "btn2", value: "Edgar"},{type: "newcolumn", offsetLeft: 20},{type: "button", name: "btn3", value: "Renee"}]},{type: "block", width: 500, list: [{type: "input", name: "name", label: "Name"},{type: "input", name: "email", label: "E-mail"},{type: "input", name: "age", label: "Age", width: 70},{type: "select", name: "sex", label: "Sex", width: 70, options:[{text: "Male", value: "m"},{text: "Female", value: "f"}]},{type: "container", name: "userList", label: "Ordered items", inputWidth: 330, inputHeight: 200},{type: "hidden", name: "grid"}]}];
// server script name will loaded in “hidden” item with form data
var inProgress = false;
function doOnLoad() {
myForm = new dhtmlXForm("myForm", formData);
myForm.attachEvent("onButtonClick", function(name){
if (name.match(/^btn\d$/) != null && inProgress == false) {
updateForm(name.replace(/btn/,""));
}
});
myGrid = new dhtmlXGridObject(myForm.getContainer("userList"));
myGrid.setSkin("dhx_skyblue");
myGrid.setImagePath("codebase/imgs/");
// 1st load
updateForm(1);
}
function updateForm(index) {
//what is the best way to do it?
}

It seems like it exactly the way you need:
function updateForm(index) {
inProgress = true;
myForm.load("xml/user"+index+".xml", function(){
// reload grid here
myGrid.clearAll();
myGrid.loadXML("xml/"+myForm.getItemValue("grid"), function(){
inProgress = false;
});
});
}

Related

Placing information inside the chart series

I have the chart bellow and I want to add the percentage to the series body. Like I manipulate the image bellow in red.
how Is this possible?
https://codesandbox.io/s/label-line-adjust-forked-09ukre?file=/index.js
var dom = document.getElementById("chart-container");
var myChart = echarts.init(dom, null, {
renderer: "canvas",
useDirtyRect: false
});
var app = {};
var option;
var datas = [
////////////////////////////////////////
[
{ name: "test1", value: 20 },
{ name: "test2", value: 40 },
{ name: "test3", value: 40 }
]
];
option = {
title: {
text: "test",
left: "center",
textStyle: {
color: "#999",
fontWeight: "normal",
fontSize: 14
}
},
series: datas.map(function (data, idx) {
return {
type: "pie",
radius: [80, 160],
top: "10%",
height: "33.33%",
left: "center",
width: 400,
itemStyle: {
borderColor: "#fff",
borderWidth: 1
},
label: {
alignTo: "edge",
minMargin: 5,
edgeDistance: 10,
lineHeight: 15,
rich: {
time: {
fontSize: 10,
color: "#999"
}
}
},
labelLine: {
length: 15,
length2: 0,
maxSurfaceAngle: 80
},
data: data
};
})
};
if (option && typeof option === "object") {
myChart.setOption(option);
}
window.addEventListener("resize", myChart.resize);
Thanks
To place information inside the chart, you have to use position: "inside" in the label. Set what is put inside the label with the formatter. (Here, {c} is the value of a data item)
label: {
formatter: "{c}%",
position: "inside"
},
But it seems that it's not possible to have both a label inside AND one outside the same chart (like in your image). However, a workaround can do the job here. Like using 2 identical series except one has the label from your example code, and one has the label code I wrote above. One chart will be on top of the other (wich is a bit messy) but the result will be as you want :

Split dhtmlxForm attached to dhtmlxSidebar

I have a problem with a split-form which is attached to a dhtmlxSidebar. Unfortunately the dhtmlxEditor doesn’t work that way and is read only somehow.
Here's my dhtmlxForm structure:
var formData_technik = [
{ type: "settings", position: "label-left"},
{ type: "block", id: "eintragung", inputWidth: 650, list: [
{ type: "combo", label: "Studio: ", inputWidth: 200, labelWidth: 60, name: "technik_studio", required: "true" },
{ type: "input", label: "Problem", name: "technik_problem", rows: "1", selected: "true", labelWidth: 60, inputWidth: 450, required: "true", note: {text: "kurze Beschreibung"}},
{ type: 'editor', name: 'technik_detail', label: 'Problembeschreibung', labelWidth: 400, inputWidth: 620, inputHeight: 240, value: "" },
{ type: "combo", label: "Eingetragen von", name: "technik_user", inputWidth: 200, labelWidth: 70, disabled: true }
]},
{ type: "block", id: "bearbeitet", list: [
{ type: "checkbox", label: "Problem behoben", name: "technik_behoben", inputWidth: 20, position: "label-right" },
{ type: "combo", label: "Behoben von", name: "technik_behobenvon", inputWidth: 200, labelWidth: 90, disabled: true },
{ type: "calendar", label: "Behoben am", name: "technik_behobenwann", dateFormat: "%d.%m.%Y %H:%i", serverDateFormat: "%Y-%m-%d %H:%i:%s", enableTime: "true", labelWidth: 90, inputWidth: 120, disabled: true },
{ type: 'editor', name: 'technik_behobenkommentar', label: 'Problembeschreibung', labelWidth: 400, inputWidth: 620, inputHeight: 240, value: "" }
]}
];
var initValues = {technik_behobenkommentar: "123 234 345"};
May be this approach could help you:
mySidebar = new dhtmlXSideBar({ parent: "sidebarObj", icons_path: "win_16x16/", width: 160, items: [ {id: "recent", text: "Recent", icon: "recent.png", selected: true}, {id: "desktop", text: "Desktop", icon: "desktop.png"}] });
myForm = mySidebar.cells("recent").attachForm(formData_technik);
mySidebar.cells("desktop").attachObject("bearbeitet");
mySidebar.attachEvent("onSelect", function(id){
if (id == "recent" || id == "desktop") {
var editorId = {recent:"technik_detail", desktop: "technik_behobenkommentar"}[id];
myForm.getEditor(editorId)._prepareContent(true);
myForm.setItemValue(editorId, initValues[editorId]);
initValues[editorId] = null;
}
});

Submit all of grid rows with Extjs form submit

I have a grid panel in a form. Any row of the grid panel have a filefield. I want to send any row (name field and filename field) to server.
Model:
Ext.define('FM.model.DefineCode', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'filename', type: 'string'}
],
validations: [
{type: 'presence', field: 'id'},
{type: 'presence', field: 'name'},
{type: 'presence', field: 'filename'}
]
});
Store:
Ext.define('FM.store.DefineCode', {
extend: 'Ext.data.Store',
model: 'FM.model.DefineCode',
autoLoad: true,
data: []
});
View:
Ext.define('FM.view.map.DefineCode', {
extend: 'Ext.window.Window',
title: 'Define Code',
alias: 'widget.mmDefineCode',
width: 600,
modal: true,
items: [{
xtype: 'form',
items: [{
xtype: 'gridpanel',
title: 'myGrid',
store: 'DefineCode',
columns: [
{
text: 'Id',
xtype: 'rownumberer',
width: 20
}, {
text: 'Name',
dataIndex: 'name',
flex: 1,
editor:{
xtype: 'textfield'
}
}, {
text: 'File',
dataIndex: 'filename',
width: 200,
editor:{
xtype: 'filefield',
emptyText: 'Select your Icon',
name: 'photo-path',
buttonText: '',
flex: 1,
buttonConfig: {
iconCls: 'icon-upload-18x18'
},
listeners: {
change: function(e, ee, eee) {
var grid = this.up('grid');
var store = grid.getStore();
var newStore = Ext.create('FM.store.DefineCode',{});
store.insert(store.data.items.length, newStore);
}
}
},
}, {
text: '',
width: 40
}
],
height: 200,
width: 600,
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
]}
],
}],
buttons: [{text: 'OK', action: 'OK'}],
initComponent: function() {
var me = this;
Ext.apply(me, {});
me.callParent(arguments);
}
});
Controller:
...
form.submit({
url: 'icon/create',
});
When I submit form, only last row is sending to server.
Where is problem?
Why you using this ?
var newStore = Ext.create('FM.store.Path', {});
store.insert(store.data.items.length, newStore);
try using rowEditing to edit/submit 1 row data :
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 2,
clicksToMoveEditor: 1,
listeners: {
'validateedit': function(editor, e) {},
'afteredit': function(editor, e) {
var me = this;
var jsonData = Ext.encode(e.record.data);
Ext.Ajax.request({
method: 'POST',
url: 'your_url/save',
params: {data: jsonData},
success: function(response){
e.store.reload({
callback: function(){
var newRecordIndex = e.store.findBy(
function(record, filename) {
if (record.get('filename') === e.record.data.filename) {
return true;
}
return false;
}
);
me.grid.getSelectionModel().select(newRecordIndex);
}
});
}
});
return true;
}
}
});
and place it to your plugin.
I don't try it first, but may be this will help you a little.
AND this is for your controller to add a record from your grid, you need a button to trigger this function.
createRecord: function() {
var model = Ext.ModelMgr.getModel('FM.model.DefineCode');
var r = Ext.ModelManager.create({
id: '',
name: '',
filename: ''
}, model);
this.getYourgrid().getStore().insert(0, r);
this.getYourgrid().rowEditing.startEdit(0, 0);
}
check this for your need, this is look a like. You need to specify the content-type.
And for your java need, please read this method to upload a file.

validateValue : function(value) return alert 3 times

I am using extjs version 3.1.0.
I create one simple code, which show alert message, if length of text entered is 12.
suppose i entered (123456123456), then it is showing alert message i.e(Test) 3 times.
My complete code is
Ext.onReady(function() {
Ext.QuickTips.init();
var searchForm = new Ext.form.FormPanel({
id: "searchForm",
renderTo: Ext.getBody(),
items: [ {
id: "itemUpc",
fieldLabel: 'UPC',
xtype: 'numberfield',
labelStyle: 'font-size: x-large',
height: '35px',
name: 'itemUpc',
validateValue : function(value){
if(value.length ==12){
alert("Test");
return false;
}
return false;
}
}]
});
});
Please help me.
if you want to restrict length, use minLength and maxLength properties
Ext.onReady(function() {
Ext.QuickTips.init();
var searchForm = new Ext.form.FormPanel({
id: "searchForm",
renderTo: Ext.getBody(),
items: [ {
id: "itemUpc",
fieldLabel: 'UPC',
xtype: 'numberfield',
labelStyle: 'font-size: x-large',
height: '35px',
name: 'itemUpc',
maxLength : 12,
minLength : 12
} ]
});
});

Dojo-DataGrid :: How to dynamically fetch values as options for a select box in Dojo DataGrid

I have a Dojo-DataGrid which is programatically populated as below :
var jsonStore = new dojo.data.ItemFileWriteStore({ url: "json/gaskets.json" });
var layout= [
{ field: "description", width: "auto", name: "Tier/Description", editable:true },
{ field: "billingMethod", width: "auto", name: "Billing Method", editable: true,
type: dojox.grid.cells.Select, options: [ '0', '1' ] },
{ field: "offeringComponents", width: "auto", name: "Offering Component", editable: true,
type: dojox.grid.cells.Select, options: [ '0', '1' ] },
{ field: "serviceActivity", width: "auto", name: "Service Activity", editable: true,
type: dojox.grid.cells.Select, options: [ '0', '1' ] },
{ field: "hours", width: "auto", name: "Hours" },
{ field: "rate", width: "auto", name: "Rate <br/> (EUR)" },
{ field: "cost", width: "auto", name: "Cost <br/> (EUR)" },
{ field: "price", width: "auto", name: "Price <br/> (EUR)" },
{ field: "gvn", width: "auto", name: "Gvn" }
];
grid = new dojox.grid.DataGrid({
query: { description: '*' },
store: jsonStore,
structure: layout,
rowsPerPage: 20
}, 'gridNode');
The options for the field billingMethod (Currently defined as dojox.grid.cells.Select) are hard coded right now, but I would like to get those values dynamically from the backend as JSON. But dojox.grid.cells.Select currently(I am using Dojo 1.5) does not have a option to define a "store".
I am trying to use dijit.form.FilteringSelect, but this needs a id(of a Div) for its constructor and I cannot specify one as this select box has to go with in the grid, rather than a separate DIV.
Thanks
Sandeep
Your answer works fine, the issue is that in the combo the user can select A, but once the combo lose the focus, the value 1 will be shown. Some months ago I had the same problem, and I got a solution from KGF on #dojo. The idea is to have a formatter on the cell that just creates a SPAN element, and then it invokes a query over the store to get the label of the selected element and put it on the SPAN. I modified your example to get that working.
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojox.grid.cells.dijit");
dojo.require("dojox.grid.DataGrid");
dojo.require("dijit.form.Select");
dojo.require('dojox.grid.cells.dijit');
dojo.require('dijit.form.FilteringSelect');
var grid;
var jsonStore;
dojo.addOnLoad(function() {
jsonStore = new dojo.data.ItemFileWriteStore({
data: {
"identifier": "identify",
"label": "description",
"items": [
{
"identify": 123,
"description": "Project Manager"},
{
"identify": 234,
"description": "Developer"},
{
"identify": 536,
"description": "Developer",
"billingMethod":2}
]
}
});
var myStore = new dojo.data.ItemFileReadStore({
data: {
identifier: 'value',
label: 'name',
items: [{
value: 1,
name: 'A',
label: 'A'},
{
value: 2,
name: 'B',
label: 'B'},
{
value: 3,
name: 'C',
label: 'C'}]
}
});
//[kgf] callback referenced by formatter for FilteringSelect cell
function displayValue(nodeId, store, attr, item) {
if (item != null) { //if it's null, it wasn't found!
dojo.byId(nodeId).innerHTML = store.getValue(item, attr);
}
}
var layout = [
{
field: "identify",
width: "auto",
name: "Id 2 Hide",
hidden: true},
{
field: "description",
width: "auto",
name: "Tier/Description",
editable: true},
{
field: 'billingMethod',
name: 'Billing Method',
editable: true,
required: true,
width: '150px',
type: dojox.grid.cells._Widget,
widgetClass: dijit.form.FilteringSelect,
widgetProps: {
store: myStore
},
formatter: function(data, rowIndex) { //[kgf]
//alert("data "+data)
var genId = 'title' + rowIndex;
var store = this.widgetProps.store;
var attr = "label";
setTimeout(function() {
store.fetchItemByIdentity({
identity: data,
onItem: dojo.partial(displayValue, genId, store, attr)
});
}, 50);
//for now return a span with a predetermined id for us to populate.
return '<span id="' + genId + '"></span>';
}
}
];
grid = new dojox.grid.DataGrid({
query: {
description: '*'
},
store: jsonStore,
singleClickEdit: true,
structure: layout,
rowsPerPage: 20
}, 'gridNode');
grid.startup();
});
I was finally able to figure this out..Incase someone wants to implement same kind of stuff using DOJO Datagrid+FilteringSelect.
Sample Code
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojox.grid.cells.dijit");
dojo.require("dojox.grid.DataGrid");
dojo.require("dijit.form.Select");
dojo.require('dojox.grid.cells.dijit');
dojo.require('dijit.form.FilteringSelect');
var grid;
var jsonStore;
dojo.addOnLoad(function() {
jsonStore = new dojo.data.ItemFileWriteStore({
data: {
"identifier": "identify",
"label": "description",
"items": [
{
"identify": 123,
"description": "Project Manager"},
{
"identify": 234,
"description": "Developer"},
{
"identify": 536,
"description": "Developer"}
]
}
});
var myStore = new dojo.data.ItemFileReadStore({
data: {
identifier: 'value',
label: 'name',
items: [{
value: 1,
name: 'A',
label: 'A'},
{
value: 2,
name: 'B',
label: 'Y'},
{
value: 3,
name: 'C',
label: 'C'}]
}
});
var layout = [
{
field: "identify",
width: "auto",
name: "Id 2 Hide",
hidden: true},
{
field: "description",
width: "auto",
name: "Tier/Description",
editable: true},
{
field: 'billingMethod',
name: 'Billing Method',
editable: true,
required: true,
width: '150px',
type: dojox.grid.cells._Widget,
widgetClass: dijit.form.FilteringSelect,
widgetProps: {
store: myStore
}}
];
grid = new dojox.grid.DataGrid({
query: {
description: '*'
},
store: jsonStore,
singleClickEdit: true,
structure: layout,
rowsPerPage: 20
}, 'gridNode');
grid.startup();
});