widgets (dijit.form.Button) in dojox.data.Grid - grid

I was able to put a dijit.form.DateTextBox and a dijit.form.ComboBox in a dojox.grid.DataGrid but not a dijit.form.Button. I have not tried with other widgets.
new dojox.grid.DataGrid({
store: new dojo.data.ItemFileReadStore({data: {items: [{option: 'option A', date:'10/31/2011'},{option: option B'}]}}),
structure:[{
field: "option",
editable: true,
type: dojox.grid.cells._Widget,
widgetClass: dijit.form.ComboBox,
widgetProps: {
store: new dojo.data.ItemFileReadStore({data: {items: [{option: 'option A'},{position: option B'}]}}),
searchAttr: 'option'
},{
field: 'date',
editable: true,
type: dojox.grid.cells.DateTextBox,
widgetProps: {selector: "date"},
formatter: function(v) {if (v) return dojo.date.locale.format(new Date(v),{selector: 'date'})}
},{
field: "button",
type: dojox.grid.cells._Widget,
editable: true,
widgetClass: dijit.form.Button,
widgetProps: {style: {width: "100px"},label: "dijit button?"}
}]
})
Salu2,
Jose Leviaguirre

It seems that since 1.4, the grid can handle dijits via formatter
{
field: "button",
type: dojox.grid.cells._Widget,
editable: false,
formatter: function(){
return new dijit.form.Button({label:"test"})
}
Here is working sample solution: http://jsfiddle.net/jleviaguirre/u3QFj/5/

Related

Extjs combobox drop down list not align with combo box

I have combo box with some values. When i click the combo listed down the data. but there not align with combo box and popup listed.
any help
/**
* This is the combo box with common values
*/
var combo_1 = Ext.extend(Ext.form.ComboBox, {
editable:true,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
anchor:'95%',
forceSelection: true,
tabIndex: 1,
labelStyle: 'width:110px'
});
/**
* This is the form panal
*/
var form_panal = new Ext.form.FormPanel({
id:'form_panal',
frame:true,
bodyStyle:'padding:10px 10px 10px 10px',
buttonAlign:'center',
items: [
combo_1,
combo_2,
combo_3,
combo_4
],
buttons: [ {
text: 'Save',
handler : function(){
}
},
{text: 'Cancel',
handler : function() {
}
}
]
});
enter image description here
Here is the sample code
Ext.application({
name : 'Fiddle',
launch : function() {
var combo_1 = Ext.create('Ext.form.field.ComboBox', {
editable:true,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
anchor:'95%',
forceSelection: true,
tabIndex: 1,
labelStyle: 'width:110px',
displayField: 'name',
valueField: 'name',
store: {
fields: [{
name: 'name'
}],
proxy: {
type: 'memory'
},
data: [{
name: 'Android'
},{
name: 'iOS'
}, {
name: 'Windows'
}]
}
});
var combo_2 = Ext.create('Ext.form.field.ComboBox', {
editable:true,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
anchor:'95%',
forceSelection: true,
tabIndex: 1,
labelStyle: 'width:110px',
displayField: 'name1',
valueField: 'name1',
store: {
fields: [{
name: 'name1'
}],
proxy: {
type: 'memory'
},
data: [{
name1: 'Blue Star'
},{
name1: 'LLoyd'
}, {
name1: 'Samsung'
}]
}
});
var combo_3 = Ext.create('Ext.form.field.ComboBox', {
editable:true,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
selectOnFocus:true,
anchor:'95%',
forceSelection: true,
tabIndex: 1,
labelStyle: 'width:110px',
displayField: 'name2',
valueField: 'name2',
store: {
fields: [{
name: 'name2'
}],
proxy: {
type: 'memory'
},
data: [{
name2: 'Andhra pradesh'
},{
name2: 'Telangana'
}, {
name2: 'Karnataka'
}]
}
});
/**
* This is the form panal
*/
Ext.create('Ext.form.FormPanel',{
frame:true,
bodyStyle:'padding:10px 10px 10px 10px',
buttonAlign:'center',
items: [
combo_1,
combo_2,
combo_3
],
buttons: [ {
text: 'Save',
handler : function(){
}
},{
text: 'Cancel',
handler : function() {
}
}],
renderTo: document.body
});
}
});

how to change the color of the value in textfield using tags <span> in ext js

How to specify tags in the value of the textfield in ext js.
my code:
var myText = new Ext.form.TextField({
readOnly: true,
id: "key",
cls:"overflowText",
value: '<span style="color:red">'+name+'</span>',
});
This doesnt apply color to the value.How can i do it?
Use the fieldCls property, you shouldn't need the span.
Fiddle
// Style
<style>
.overflowText {
color: red;
}
</style>
// Code
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.create('Ext.Panel', {
width: 500,
height: 300,
title: "FormLayout Panel",
layout: 'form',
renderTo: Ext.getBody(),
bodyPadding: 5,
defaultType: 'textfield',
items: [{
fieldLabel: 'First Name',
name: 'first',
fieldCls: 'overflowText',
allowBlank: false
}, {
fieldLabel: 'Last Name',
name: 'last'
}, {
fieldLabel: 'Company',
name: 'company'
}, {
fieldLabel: 'Email',
name: 'email',
vtype: 'email'
}, {
fieldLabel: 'DOB',
name: 'dob',
xtype: 'datefield'
}, {
fieldLabel: 'Age',
name: 'age',
xtype: 'numberfield',
minValue: 0,
maxValue: 100
}, {
xtype: 'timefield',
fieldLabel: 'Time',
name: 'time',
minValue: '8:00am',
maxValue: '6:00pm'
}]
});
}
});
Maybe it happens because style rule is missing semicolon at the end? So it should be <span style="color:red;">

Having some trouble reading JSON response

I make an ajax request to the servlet that returns the result of a database query.
I can see with firebug the response and I want to put these results in a list (or other..) that I have already created.
I tried to read this post but it didn't help me..
Code:
this is the ajax request:
Ext.Ajax.request({
url: '/VIProject/Container',
success: function (action){alert('Lista caricata!'); console.debug(action); },
failure: function (){alert('Errore nel caricamento...');},
headers: {
'my-header': 'foo'
},
params: { action: "GETCONTAINERLIST" }
});
response from servlet(firebug):
{"message":"OK","container":[{"idOrdine":"1","numLotto":"123"},{"idOrdine":"2","numLotto":"321"},{"idOrdine":"3","numLotto":"876"}],"success":true}
list:
var listView = Ext.create('Ext.grid.Panel', {
width:425,
height:250,
id: 'lista',
collapsible:true,
title:'Simple ListView <i>(0 items selected)</i>',
store: //???
multiSelect: true,
viewConfig: {
emptyText: 'No images to display'
},
columns: [{
text: 'idOrdine',
flex: 15,
sortable: true,
dataIndex: 'idOrdine'
},{
text: 'Last Modified',
flex: 20,
sortable: true,
dataIndex: 'numLotto'
}]
});
How can I do?
I've modified your code to use a store:
Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: ['idOrdine', 'numLotto']
})
var listView = Ext.create('Ext.grid.Panel', {
width:425,
height:250,
id: 'lista',
collapsible:true,
title:'Simple ListView <i>(0 items selected)</i>',
store: store: {
model: MyModel,
autoLoad: true,
proxy: {
type: 'ajax',
url: '/VIProject/Container',
reader: {
type: 'json',
root: 'container'
}
}
},
multiSelect: true,
viewConfig: {
emptyText: 'No images to display'
},
columns: [{
text: 'idOrdine',
flex: 15,
sortable: true,
dataIndex: 'idOrdine'
},{
text: 'Last Modified',
flex: 20,
sortable: true,
dataIndex: 'numLotto'
}]
});
Even in this way it works:
var proxy=new Ext.data.HttpProxy({url:'/VIProject/Container'});
var reader=new Ext.data.JsonReader({},[
{name: 'idOrdine', mapping: 'idOrdine'},
{name: 'numLotto', mapping: 'numLotto'}
]);
var store=new Ext.data.Store( {
proxy:proxy,
reader:reader
});
store.load();
I tried in every way.. but i don't know what to do!

jqgrid jsonReader configuration

I'm new to jqgrid finally i've setup a grid. Suppose i need to setup jsonReader so that the grid knows where to get my grid-data in the json return. However i got blank cells after trying for days.
Here is my grid:
jQuery("#list48").jqGrid({
url: 'dbtest.aspx/get_offsite_history2',
datatype: "json",
mtype: 'POST',
ajaxGridOptions: { contentType: "application/json" },
serializeGridData: function(postData) {
return JSON.stringify(postData);
},
jsonReader: {
root: function(obj) { alert(JSON.stringify(obj.d)); return obj.d; },
repeatitems: false
},
height: 'auto',
rowNum: 30,
rowList: [10, 20, 30],
colNames: ['name', 'start_date', 'duration', 'offsite_cat'],
colModel: [
{ name: 'name', index: 'name', width: 80, align: 'left', editable: true, edittype: 'text' },
{ name: 'start_date', index: 'start_date', width: 120, align: 'left', editable: true, edittype: 'text' },
{ name: 'duration', index: 'duration', width: 120, align: 'left', editable: true, edittype: 'text' },
{ name: 'offsite_cat', index: 'offsite_cat', width: 120, align: 'left', editable: true, edittype: 'text'}],
pager: "#plist48",
viewrecords: true,
sortname: 'name',
caption: "Grouping Array Data",
gridview: true
});
This is the server return from url dbtest.aspx/get_offsite_history2:
{"d":"[{\"name\":\"A\",\"start_date\":\"B\",\"duration\":\"C\",\"offsite_cat\":\"D\"}]"}
i suppose to get the result by setting "root: 'd'" but i got 64 blank rows for that...
look for comments... many thanks
The reason of your problem is the bug in your server code. You make serialization to JSON twice. After deserializing of d property of the server response you get still JSON string (!!!) instead of object. Typical error is manual usage of JavaScriptSerializer.Serialize in the web method. One should return the object itself instead of the string which is the result of serializing.
Without modifying of your current server code you can fix the problem by usage of
jsonReader: {
root: function (obj) {
alert(typeof obj.d === "string" ? obj.d : JSON.stringify(obj.d));
return typeof obj.d === "string" ? $.parseJSON(obj.d) : obj.d;
},
repeatitems: false,
page: function () { return 1; },
total: function () { return 1; },
records: function (obj) {
return typeof obj.d === "string" ? $.parseJSON(obj.d).length : obj.length;
}
}
or (if you use loadonce: true) just
jsonReader: {
root: function (obj) {
return typeof obj.d === "string" ? $.parseJSON(obj.d) : obj.d;
},
repeatitems: false
}
Because your current server code seems not implemented the paging of data you should increase rowNum to some large enough value like rowNum: 10000 or to use loadonce: true.
UPDATED: You can find here modified demo which works. It displays
after the alert message.
I think the problem is the structure of your returned json data.
Below is one that I use :
{ "page":1,
"rows":[{"id":"1","cell":["1","1","Row 1","3","9",""]},
{"id":"2","cell":["2","2","Row 2","2","1",""]},
{"id":"3","cell":["3","4","Row 3","2","0",""]}],
"records":3,
"total":1
}
You may need to add a colModel for id to uniquely identify each row.
e.g.
colNames: ['id', 'name', 'start_date', 'duration', 'offsite_cat'],
colModel: [
{ name: 'id', index: 'id', hidden: true },
{ name: 'name', index: 'name', width: 80, align: 'left', editable: true, edittype: 'text' },
{ name: 'start_date', index: 'start_date', width: 120, align: 'left', editable: true, edittype: 'text' },
{ name: 'duration', index: 'duration', width: 120, align: 'left', editable: true, edittype: 'text' },
{ name: 'offsite_cat', index: 'offsite_cat', width: 120, align: 'left', editable: true, edittype: 'text'}],
Hope that helps.

I could not able to see Add. Edit, Delete and View using JQGrid

I have
jQuery(document).ready(function () {
jQuery("#list").jqGrid({
url: '/TabMaster/GetGridData',
datatype: 'json',
mtype: 'GET',
colNames: ['col ID', 'First Name', 'Last Name', '', '', '', ''],
colModel: [
{ name: 'colID', index: 'colID', width: 100, align: 'left' },
{ name: 'FirstName', index: 'FirstName', width: 150, align: 'left' },
{ name: 'LastName', index: 'LastName', width: 300, align: 'left' },
{ name: 'add', width: 18, sortable: false, search: false,
formatter: function () {
return "<span class='ui-icon ui-icon-plus'></span>"
}
},
{ name: 'edit', width: 18, sortable: false, search: false,
formatter: function () {
return "<span class='ui-icon ui-icon-pencil'></span>"
}
},
{ name: 'del', width: 18, sortable: false, search: false,
formatter: function () {
return "<span class='ui-icon ui-icon-trash'></span>"
}
},
{ name: 'details', width: 18, sortable: false, search: false,
formatter: function () {
return "<span class='ui-icon ui-icon-document'></span>"
}
}
],
onSelectRow: function (rowJsonId)
{ handleSelectedRow(rowJsonId); },
pager: jQuery('#pager'),
rowNum: 4,
rowList: [1, 2, 4, 5, 10],
sortname: 'colID',
sortorder: "asc",
viewrecords: true,
gridview: true,
rownumbers: true,
multiselect: true,
imgpath: '/scripts/themes/steel/images',
caption: 'Tab Master Information'
}).navGrid(pager, { edit: true, add: true, del: true, refresh: true, search: true });
});
function handleSelectedRow(thing) {
}
but i could not able to see buttons for Add, Edit, Delete and View i am only able to see for empty column in JQGrid.
for your reference
Please provide your valuable comments for the same.
It seems to me that you try to use my demo from the answer:
All classes for the ui-icon-plus, ui-icon-trash and so on come from jQuery UI CSS. You shoul just verify that you included jQuery UI correctly together with the images subdirectory.

Resources