I am new in ExtJS and I need your help to create a Grid with two scales, the first one in the first column of the grid(Financial, Technical..), and the second one in the first row of the grid(J+1, J+2..), and for every column/row index there's a combobox to make assessments, like this :
show image
Can anyone help me please ?
Thank you very much.
Ext.onReady(function () {
var renderer = function (val) {
var loop = ['Barney','Fred'];
var str = '<select name="first">';
for(var i = 0; i < loop.length ; i++){
if(val === loop[i]){
str += '<option value="'+loop[i]+'" selected>'+loop[i]+'</option>';
}else{
str += '<option value="'+loop[i]+'">'+loop[i]+'</option>';
}
}
str += '</select>';
return str;
};
var rt = Ext.data.Record.create([{
name: 'id'
}, {
name: 'fullname'
}, {
name: 'first'
}]);
var myStore = new Ext.data.Store({
// explicitly create reader
reader: new Ext.data.ArrayReader({
idIndex: 0 // id for each record will be the first element
},
rt // recordType
)
});
var grid = new Ext.grid.GridPanel({
renderTo: Ext.getBody(),
store: myStore,
colModel: new Ext.grid.ColumnModel({
defaults: {
width: 120,
sortable: true
},
columns: [{
header: '',
dataIndex: 'fullname'
}, {
header: '1',
dataIndex: 'first',
renderer : renderer
}, {
header: '2',
dataIndex: 'first',
renderer : renderer
}, {
header: '3',
dataIndex: 'first',
renderer : renderer
}, {
header: '4',
dataIndex: 'first',
renderer : renderer
}]
}),
//sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
width: 600,
height: 300,
frame: true,
title: 'Framed with Row Selection and Horizontal Scrolling',
iconCls: 'icon-grid'
});
var myData = [
[1, 'Fred Flintstone', 'Fred'], // note that id for the record is the first element
[2, 'Barney Rubble', 'Barney']
];
myStore.loadData(myData);
});
Please refer fiddle.
Hope this helps.
Related
I am new to ExtJS and I am trying to display the group of checkboxes in this way:
I have the following code:
Ext.onReady(function() {
var ct = Ext.create('Ext.container.Viewport', {
layout: 'border',
defaults: {
collapsible: true,
split: true
},
items: [{
title: 'Tasks',
region: 'west',
margins: '5 0 0 0',
cmargins: '5 5 0 0',
width: '50%',
scrollable: true,
bodyStyle: 'padding:10px',
html: MyTest.description
},{
collapsible: false,
region: 'center',
margins: '5 0 0 0',
items: [{
xtype: 'grid',
id: 'MyGridPanel',
title: 'Test Grid',
store: {
fields: ['name', 'permissions'],
proxy: {
type: 'memory',
reader: {type: 'json'}
},
data: [{
name: 'Farms',
permissions:{
'manage': 1,
'clone': 1,
'launch': 0,
'terminate': 0,
'not-owned-farms': 0
}
},{
name: 'Alerts',
permissions:null
},{
name: 'Servers',
permissions:null
},{
name: 'Events and notifications',
permissions:null
},{
name: 'Statistics',
permissions:null
},{
name: 'Roles',
permissions:{
'manage':1,
'clone':0,
'bundletasks':0
}
},{
name: 'Scripts',
permissions:{
'manage':0,
'execute':0,
'fork':0
}
}]
},
columns: [{
text: 'Name',
width: 200,
dataIndex: 'name'
},{
text: 'Permissions',
dataIndex: 'permissions',
// I need to insert here a checkbox groups for elements that have permissions I guess. So what should I use here - renderer, handle?
}],
}]
}]
});
So what should I use for that? For example if I use renderer (not sure if it's ok to use it) I can receive all the data for checkboxes (see code below), but I am not sure how to render it.
renderer: function(value, meta, rec, rowIdx, colIdx, store, view) {
var checkboxconfigs = [];
for (var variable in value) {
checkboxconfigs.push({
boxLabel: variable,
name: variable,
inputValue: value[variable],
checked: value[variable]
})
}
var checkboxes = new Ext.form.CheckboxGroup({
id:'chkGroup',
fieldLabel: 'Permissions',
columns: 1,
items: checkboxconfigs
});
// return WHAT?;
}
I would be grateful for help!
Solution:
If you want to render the values, try with this column definition:
{
text: 'Permissions',
dataIndex: 'permissions',
width: 200,
renderer: function(value, cell) {
var s = '';
for (var index in value) {
s = s + '<input type="checkbox" ';
if (value[index] == 1) {
s = s + 'checked';
};
s = s + '>' + index;
}
return s;
}
}
Notes:
Tested with ExtJS 4.2.
You can do it like below:
renderer: function (value, meta, rec, rowIdx, colIdx, store, view) {
var doms = '';
for (var variable in value) {
var temp = value[variable] === 1 ? 'checked' : '';
doms += '<input type="checkbox" name="' + variable + '" value="Car" ' + temp + '>' + variable
}
return doms;
}
Working fiddle.
I am displaying checkboxgroup on a window with other fields too.
But the second time I call the function to display this window with the checkboxgroup the checkboxgroup gets duplicated.
i.e It only displays two times and not multiple times.
Eg : If actual checkbox values are "red" , "green" then the result on second ,third call will be "red" , "red" , "green" , "green".
Even the +Checklist button displays twice on second or more calls.
It displays proper values on first call though.
below is the code I am working on.
var checkboxconfigs = [];
function showassetForm(record,statusname,emptyval)
{
var arrSubTicket = getSubTickets(record.data.Id);
for(z=0;z<arrSubTicket.length;z++)
{
checkboxconfigs.push({ //pushing into array
id:arrSubTicket[z].Id,
boxLabel:arrSubTicket[z].Name,
name:'checklist',
inputValue:arrSubTicket[z].Id,
relatedTicket:arrSubTicket[z].TicketId
//any other checkbox properties, layout related or whatever
});
}
var myCheckboxGroup = Ext.create('Ext.form.CheckboxGroup', {
columns: 1,
vertical: true,
items: checkboxconfigs
});
myCheckboxGroup.on({
change: function(checkboxGroup, newValue) {
formattedValues = [];
newValue = newValue.checklist.length === 0 ? [newValue.checklist] : newValue.checklist;
checkboxGroup.items.each(function(checkbox){
var checkboxValue = checkbox.inputValue,
foramttedValue = {};
foramttedValue[checkboxValue] = newValue.indexOf(checkboxValue) !== -1 ? 'on' : 'off';
formattedValues.push(foramttedValue);
});
}
});
form = Ext.widget('form', {
layout: {
type: 'vbox',
align: 'stretch'
},
border: false,
bodyPadding: 10,
fieldDefaults: {
labelAlign: 'top',
labelWidth: 100,
labelStyle: 'font-weight:bold'
},
defaults: {
margins: '0 0 10 0'
},
items: [{
xtype: 'fieldcontainer',
labelStyle: 'font-weight:bold;padding:0',
layout: 'vbox',
defaultType: 'textfield',
fieldDefaults: {
labelAlign: 'left'
},
items: [
/*{
flex: 1,
name: 'Name',
fieldLabel: 'Ticket Description',
allowBlank: true
},*/
{
name: 'Hours',
fieldLabel: 'Hours',
allowBlank: true,
value: record.data.Hours
},
{
flex: 2,
xtype:'textarea',
name: 'Notes',
fieldLabel: 'Ticket Notes',
allowBlank: true
},
{
xtype: 'combo',
fieldLabel: 'Status',
hiddenName: 'Status',
allowBlank: false,
name:'Status',
store: new Ext.data.SimpleStore({
data: allstatus,
id: 0,
fields: ['value', 'text']
}),
// valueField: 'value',
valueField: 'value',
displayField: 'text',
triggerAction: 'all',
editable: false,
// value : record.data.Status
value : statusname
},
{
xtype: 'combo',
fieldLabel: 'Priority',
hiddenName: 'Priority',
allowBlank: false,
name:'Priority',
store: new Ext.data.SimpleStore({
data: priorities,
id: 0,
fields: ['value', 'text']
}),
// valueField: 'value',
valueField: 'value',
displayField: 'text',
triggerAction: 'all',
editable: false,
value : record.data.Priority
},
{
xtype: 'button',
id: 'newSubTicket',
cls:'x-btn-default-small',
text: '+ Checklist',
handler : function () {
createSubticket(record,statusname);
},
style : 'margin:0 0px'
},
myCheckboxGroup
]
}],
buttons: [{
text: 'Cancel',
handler: function() {
this.up('form').getForm().reset();
this.up('window').hide();
}
}, {
text: 'Save',
handler: function() {
if (this.up('form').getForm().isValid())
{
// In a real application, this would submit the form to the configured url
// this.up('form').getForm().submit();
form = this.up('form').getForm();
var recordsToAdd = [],recordsToAddNotes = [];
var record1 = {},recordNotes = {};
//this.up('window').hide();
//var summary = form.findField('Name').getSubmitValue();
var hrs = form.findField('Hours').getSubmitValue();
var status = form.findField('Status').getSubmitValue();
var priority = form.findField('Priority').getSubmitValue();
var notes = form.findField('Notes').getSubmitValue();
record1['ccfive_related_ticket_status']=status;
record1['dev_priority']=priority;
record1['io_uuid'] = record.data.Id;
//console.log("TicketName="+record.data.TicketName);
recordsToAdd.push(record1);
recordNotes['dev_note'] = notes;
recordNotes['dev_hours'] = hrs;
recordNotes['dev_related_punchlist_item'] = record.data.Id;
recordNotes['ccfive_related_ticket_status'] = status;
recordsToAddNotes.push(recordNotes);
}
}
}]
});
win = Ext.widget('window', {
title: record.data.TicketName,
closeAction: 'hide',
width: 400,
height: 450,
minHeight: 220,
layout: 'fit',
resizable: true,
modal: true,
items: form
});
win.show();
}
This is what I get on first call
But after clicking on cancel and calling the function it displays me.
Duplicate checkboxes and checklist button on second call
Move var checkboxconfigs = []; into showassetForm function
function showassetForm(record, statusname, emptyval) {
var checkboxconfigs = [];
var arrSubTicket = getSubTickets(record.data.Id);
The issue was just of passing id to some parameters on form.
Extjs sometimes behaves weird if Id is passed.
Removed id parameter and it worked fine!
Try and avoid duplicate ids (see comment "double check this"):
for(z=0;z<arrSubTicket.length;z++)
{
checkboxconfigs.push({
id:arrSubTicket[z].Id, // <==================== double check this!!
boxLabel:arrSubTicket[z].Name,
name:'checklist',
inputValue:arrSubTicket[z].Id, // <============ double check this!!
relatedTicket:arrSubTicket[z].TicketId
});
I'm using an ExtJS (v3.4.0) GridPanel with the RowEditor extension to allow users to add lines of text to a grid. I have also used the checkcolumn extension so users can check certain lines of text for later processing. So far, it looks like this:
However, when editing a row, the problem at hand becomes apparent:
The value underlying the checkcolumn is being displayed in text form along with the actual checkbox. I figured since users can check the checkboxes without editing the row, I would make this column uneditable to fix my issue. However, after modifying my code the true/false value is still being displayed in edit mode, the text value is just not editable anymore.
My code so far:
Ext.QuickTips.init();
var FreeText = Ext.data.Record.create([{
name: 'text',
type: 'string'
}, {
name: 'active',
type: 'bool'
}]);
var store = new Ext.data.GroupingStore({
reader: new Ext.data.JsonReader({fields: FreeText}),
sortInfo: {field: 'text', direction: 'ASC'}
});
var editor = new Ext.ux.grid.RowEditor({
saveText: 'Update'
});
var freeTextPanel = new Ext.grid.GridPanel({
store: store,
width: 600,
region:'center',
margins: '0 5 5 5',
autoExpandColumn: 'text',
plugins: [editor],
view: new Ext.grid.GroupingView({
markDirty: false
}),
tbar: [{
iconCls: 'icon-add',
text: 'Add',
handler: function(){
var e = new FreeText({
text: "",
active: true
});
editor.stopEditing();
store.insert(0, e);
freeTextPanel.getView().refresh();
freeTextPanel.getSelectionModel().selectRow(0);
editor.startEditing(0);
}
},{
ref: '../removeBtn',
iconCls: 'icon-delete',
text: 'Delete',
disabled: true,
handler: function(){
editor.stopEditing();
var s = freeTextPanel.getSelectionModel().getSelections();
for(var i = 0, r; r = s[i]; i++){
store.remove(r);
}
}
}, {
xtype: 'tbseparator'
}, {
iconCls: 'icon-excel-import',
//text: 'Import from CSV',
tooltip: 'Import CSV',
handler: function() {
alert( "Excel import here!" );
}
}],
columns: [
{
xtype: 'checkcolumn',
header: 'Active',
dataIndex: 'active',
align: 'center',
width: 50
}, {
id: 'text',
header: 'Free Text',
dataIndex: 'text',
width: 220,
sortable: true,
editor: {
xtype: 'textfield',
allowBlank: false
}
}],
isCellEditable: function(col, row) {
var record = store.getAt(row);
if (record.get('active')) {
return false;
}
return Ext.grid.ColumnModel.prototype.isCellEditable.call(this, col, row);
}
});
var layout = new Ext.Panel({
title: 'Free text entry',
layout: 'border',
layoutConfig: {
columns: 1
},
width:600,
height: 600,
items: [freeTextPanel]
});
layout.render(Ext.getBody());
freeTextPanel.getSelectionModel().on('selectionchange', function(sm){
freeTextPanel.removeBtn.setDisabled(sm.getCount() < 1);
});
Is there an easy way to simply get rid of the true/false text when editing a row?
Just in case, below are my RowEditor.js and CheckColumn.js files:
RowEditor.js
http://trac.geoext.org/browser/ext/3.4.0/examples/ux/RowEditor.js?rev=2740
CheckColumn.js
http://trac.geoext.org/browser/ext/3.4.0/examples/ux/CheckColumn.js?rev=2740
Turns out the solution to my problem was rather simple.
In the startEditing method of the RowEditor.js file I added the following code. I checked implicitly on the name of my item instead of for the checkbox type, in case I still need this functionality for other checkboxes later on:
for(var i = 0, len = cm.getColumnCount(); i < len; i++){
val = this.preEditValue(record, cm.getDataIndex(i));
if( cm.getDataIndex(i) == 'active' ) {
val = "";
}
f = fields[i];
f.setValue(val);
this.values[f.id] = Ext.isEmpty(val) ? '' : val;
}
I need to display a 'Delete' link against each row in a editorgridpanel.
How do I create this link;as it is not mapped to any particular column in the store?
I tried the following but it does not display the link against the added records:
var sampleRecord = new Ext.data.Record.create([
{mapping: 'organizationId',name:'organizationId', type:'int'},
{mapping: 'name',name:'name', type:'string'},
{mapping: 'address',name:'address' , type:'int'}
]);
var s_grid= new Ext.grid.EditorGridPanel ({
.........
columns: [
{header: 'id', width: 120, sortable: false, dataIndex: 'organizationId'},
{header: 'name',width: 120, sortable: false, dataIndex: 'name'},
{header: 'address', sortable: false,width: 45, dataIndex: 'address'},
{header: '',width: 50, sortable: false, renderer:this.delRenderer }
],
.....
,
delRenderer:function (val, meta, rec, rowIdx) {
var tempStr="<div onclick=\"javascript:Ext.getCmp('" +"s_grid" + "').deAllocate(" + rowIdx + ");\" class='pointer'><span style='color:#0000FF'><u>Delete</u></span></div>";
return tempStr ;
},
deAllocate:function (rowIdx ) {
Ext.getCmp('s_grid').getStore().removeAt(rowIdx);
Ext.getCmp('s_grid').getView().refresh();
}
});
Help is appreciated.
You'd be better off using an ActionColumn. Anyway, you can also wrap a solution around custom element (link...) with the cellclick event. Here's an example showing both methods:
var grid = new Ext.grid.GridPanel({
renderTo: Ext.getBody()
,height: 300
,store: new Ext.data.JsonStore({
fields: ['id', 'name']
,data: [
{id: 1, name: 'Foo'}
,{id: 2, name: 'Bar'}
,{id: 3, name: 'Baz'}
]
})
,columns: [
{dataIndex: 'name'}
,{
xtype: 'actioncolumn'
,icon: 'http://images.agoramedia.com/everydayhealth/gcms/icon_delete_16px.gif'
,handler: function(grid, row) {
grid.store.removeAt(row);
}
}
,{
renderer: function(value, md, record, row, col, store) {
return '<a class="delete-link" href="#delete-record-' + record.id + '">Delete</a>';
}
}
]
,listeners: {
cellclick: function(grid, row, col, e) {
var el = e.getTarget('a.delete-link');
if (el) {
e.preventDefault();
grid.store.removeAt(row);
}
}
}
});
var lastId = 3;
setInterval(function() {
var store = grid.store,
record = new store.recordType({id: ++lastId, name: 'New record #' + lastId}, lastId);
store.add(record);
}, 3000);
Update
And just because I may be completely off topic on your question, I think your code is not working because when you call this:
renderer: this.delRenderer
Your not in a scope where this points to your grid (since it has not even been created at this point...). What you want to do is rather something like this:
var s_grid = new Ext.grid.EditorGridPanel ({
...
columns: [..., {
...
renderer: delRenderer
}]
});
function delRenderer() {
// FYI, `this` will be the column here
...
}
Or put the function inline in the grid definition...
You can change model by adding delete field :
{
name: 'delete',
convert: function () {
return 'delete';
}
You can then add extra column in your grid and check for link click by 'cellclick' event of the grid with some modifications.Here is the working example :
Working Fiddle.
Have a nice day :-)
The dataIndex config is required on your column, so just provide any field there (e.g. the id) and in your renderer function just ignore the value argument (as you are already doing).
I have a form panel in http://jsfiddle.net/YGQxb/
var form = Ext.create('Ext.form.Panel', {
title: 'Simple Form',
bodyPadding: 5,
items: [{
xtype: 'fieldcontainer',
fieldLabel: 'Test',
labelWidth: 50,
items: [{
xtype: 'fieldcontainer',
id: 'content',
items: [{
fieldLabel: 'Date',
xtype: 'datefield',
name: 'first',
allowBlank: false
},{
xtype: 'button',
text: 'Get position',
handler: function () {
// how to get position of items
alert('position is 1 of id:content');
}
}]
}]
}],
renderTo: Ext.getBody()
});
That has 2 items (date, button). I want to get position of date item or button item of parent has id 'content'.
Is that posible? how to do that thanks
If you are looking for parent order, http://jsfiddle.net/YGQxb/8/ it depends on where you start... You could use .up() and .down() and count until you reach the itemId you want as root parent or leaf child.
...
itemId: 'content',
...
handler: function () {
// how to get position of items
var reachedRoot = false;
var maxHops = 10;
var parent;
var cnt = 0;
while (!reachedRoot && cnt < maxHops){
parent = this.up();
cnt+=1;
if (parent.itemId == 'content') {
reachedRoot = true;
}
}
alert("Button depth from content:" + cnt);
}
...
If you are looking for index position: jsfiddle.net/YGQxb/7/
handler: function () {
// how to get position of items
var dateField = this.previousSibling();
var button = this;
var parentContainer = this.up();
alert('dateField pos: ' + parentContainer.items.keys.indexOf(dateField.id));
alert('button pos: ' + parentContainer.items.keys.indexOf(button.id));
}
If you look for XY Position... here jsfiddle.net/YGQxb/6/
You can use .up() or .down() to query parent and children ex.: .up('#content') in your case. Then use .getPosition() to get the position.
...
handler: function () {
// how to get position of items
var parent = this.up('#content');
var parentPos = parent.getPosition();
var btnPos = this.getPosition();
alert(Ext.String.format("parent Pos:{0}x{1} Button Pos: {2}x{3}",
parentPos[0],
parentPos[1],
btnPos[0],
btnPos[1])
);
}
...
You can add those itemId properties to each of your items and use getPosition() method on those items you would like to get position.
example code :
var c = new Ext.panel.Panel({ //
height: 300,
renderTo: document.body,
layout: 'auto',
items: [
{
itemId: 'p1',
title: 'Panel 1',
height: 150
},
{
itemId: 'p2',
title: 'Panel 2',
height: 150
}
]
})
p1 = c.getComponent('p1'); // not the same as Ext.getCmp()
p2 = p1.ownerCt.getComponent('p2'); // reference via a sibling
and to get position now you could use p1.getPosition()
Also your code could work like this fidle . OwnerCt points to fieldcontainer