Disable tbar button based on grid data extjs 6.2 - extjs

Conditionally i need to disable the toolbar button based on the grid json data, if status not "New"
tbarItems.push(
"->",
{
text: t('import'),
id: 'masterdata_import',
iconCls: 'pimcore_icon_import',
disabled: false,
scale: 'small',
handler: this.importJob.bind(this),
dataIndex: 'status',
renderer: function (value, rowIndex, record) {
if (value !== 'New') {
tbar.disable();
}
},
}
);
https://i.stack.imgur.com/8hVmN.png
Any idea how to do this?
Thanks

i made an example at sencha fiddle. Take a look:
https://fiddle.sencha.com/#view/editor&fiddle/2qs3
You can bind disabled parameter to parameter from viewModel, while viewModel can be updated e.g when data in store changed (event datachanged is fired).
getLayout: function () {
if (this.layout == null) {
var itemsPerPage = pimcore.helpers.grid.getDefaultPageSize(70);
this.store = pimcore.helpers.grid.buildDefaultStore(
'/admin/referenceapp/import/get-import-files?processed=0',
['date','time','sourceFileLocation','sizeReadable','status','jobReference'],
itemsPerPage,
{autoLoad: true}
);
// only when used in element context
if(this.inElementContext) {
var proxy = this.store.getProxy();
proxy.extraParams["folderDate"] = this.element.folderDate;
} else {
}
this.pagingtoolbar = pimcore.helpers.grid.buildDefaultPagingToolbar(this.store);
var tbarItems = [];
tbarItems.push(
"->",
{
text: t('import'),
id: 'masterdata_import',
iconCls: 'pimcore_icon_import',
//disabled: false,
scale: 'small',
bind: {
disabled: "{one_different_than_new}"
},
handler: this.importJob.bind(this)
}
);
var tbar = Ext.create('Ext.Toolbar', {
cls: 'main-toolbar',
items: tbarItems
});
var columns = [
{text: t("date"), sortable: true, dataIndex: 'date', flex: 100, filter: 'date'},
{text: t("time"), sortable: true, dataIndex: 'time', flex: 100, filter: 'string'},
{text: t("source_file_location"), sortable: true, dataIndex: 'sourceFileLocation', filter: 'string', flex: 200},
{text: t("size"), sortable: true, dataIndex: 'sizeReadable', filter: 'string', flex: 200},
{text: t("status"), sortable: true, dataIndex: 'status', filter: 'string', flex: 200},
{text: t("jobReference"), sortable: true, dataIndex: 'jobReference', filter: 'string', flex: 200},
];
columns.push({
xtype: 'actioncolumn',
menuText: t('delete'),
width: 40,
dataIndex: 'status',
renderer: function (value, rowIndex, record) {
if (value !== 'New') {
rowIndex.tdCls = 'importnotdelete'
}
},
disabled:false,
items: [{
tooltip: t('icon_delete_import'),
icon: "/bundles/pimcoreadmin/img/flat-color-icons/delete.svg",
handler: this.removeVersion.bind(this)
}]
});
var plugins = [];
this.grid = new Ext.grid.GridPanel({
frame: false,
title: t('plugin_referenceapp_masterdataname_importview'),
store: this.store,
region: "center",
columns: columns,
columnLines: true,
bbar: Ext.create('Ext.PagingToolbar', {
pageSize: 0,
store: this.store,
displayInfo: true,
limit:0
}),
tbar: tbar,
stripeRows: true,
autoScroll: true,
plugins: plugins,
viewConfig: {
forceFit: true
},
viewModel: {
data: {
"one_different_than_new": false
}
},
//listeners: {
// afterrender : function(model) {
// console.log(model.store.data.items);
//
// for(i = 0; i<model.store.data.items.length; i++){
//
// if (model.store.data.items[i].status !== 'New') {
// tbar.disable();
// //console.log('test');
// }
//
// else{
// //console.log('no new');
// }
// }
//
// }
//}
});
this.grid.on("rowclick", this.showDetail.bind(this));
this.detailView = new Ext.Panel({
region: "east",
minWidth: 350,
width: 350,
split: true,
layout: "fit"
});
var layoutConf = {
items: [this.grid, this.detailView],
layout: "border",
//closable: !this.inElementContext
};
if(!this.inElementContext) {
//layoutConf["title"] = t('product_versions');
}
this.layout = new Ext.Panel(layoutConf);
this.layout.on("activate", function () {
this.store.load();
var check = function () {
var isDifferentThanNew = false;
this.store.each(function (r) {
if (r.get('status') != 'New') {
isDifferentThanNew = true;
}
});
this.grid.getViewModel().set('one_different_than_new', isDifferentThanNew);
}
// Listen on datachanged and update
this.store.on('update', function (s) {
check();
});
this.store.on('datachanged', function (s) {
check();
});
check();
}.bind(this));
}
return this.layout;
},

Related

Sencha Offline Proxy

facing issue in Sencha offline proxy , when json received 100 records
offline proxy only add 50 records add in store here is my simple code
response.responseText [my ajax response], it returns reocords set
var data = Ext.decode(response.responseText);
for (var c=0; c < data.length; c++){
console.log(c);
var itemrecord = Ext.create('Inertia.model.InstallingCompany');
itemrecord.set(data[c]);
Ext.getStore('InstallingCompanies-offline').add(itemrecord);
}
console.log(c);
console.log(Ext.getStore('InstallingCompanies-offline').data.length);
For this you can use direct store.loadData() method of store.
In this FIDDLE, I have create a demo using gridpanel and Ext.data.Store. I hope this FIDDLE will help you or guide you to achieve your requirement.
Code Snippet
Ext.define('ForumThread', {
extend: 'Ext.data.Model',
fields: [
'title', 'forumtitle', 'forumid', 'username', {
name: 'replycount',
type: 'int'
}, {
name: 'lastpost',
mapping: 'lastpost',
type: 'date',
dateFormat: 'timestamp'
},
'lastposter', 'excerpt', 'threadid'
],
idProperty: 'threadid'
});
Ext.create('Ext.data.Store', {
storeId: 'topicsStore',
model: 'ForumThread'
});
function renderTopic(value, p, record) {
return Ext.String.format(
'{0}',
value,
record.data.forumtitle,
record.getId(),
record.data.forumid
);
}
Ext.create('Ext.grid.Panel', {
height: window.innerHeight,
title: 'Example of Store loadData() with GRID and Ajax Request',
renderTo: Ext.getBody(),
store: Ext.data.StoreManager.lookup('topicsStore'),
loadMask: true,
columns: [{
xtype: 'rownumberer',
width: 35,
sortable: false
}, {
tdCls: 'x-grid-cell-topic',
text: "Topic",
dataIndex: 'title',
flex: 1,
renderer: renderTopic,
sortable: true,
groupable: false,
cellWrap: true
}, {
text: "Author",
dataIndex: 'username',
flex: 0.5,
sortable: true,
groupable: false
}, {
text: "Replies",
dataIndex: 'replycount',
align: 'center',
width: 90,
sortable: false
}, {
id: 'last',
text: "Last Post",
dataIndex: 'lastpost',
flex: 0.5,
renderer: Ext.util.Format.dateRenderer('n/j/Y g:i A'),
sortable: true,
groupable: false
}],
listeners: {
afterrender: function (cmp) {
var store = Ext.data.StoreManager.lookup('topicsStore'),
store1;
cmp.getEl().mask('Please wait..!');
Ext.Ajax.request({
url: 'topics.json',
success: function (data) {
var response = Ext.decode(data.responseText);
store.loadData(response.topics);
cmp.getEl().unmask();
//Add data using store.add() method in Store
store1 = Ext.create('Ext.data.Store', {
model: 'ForumThread'
});
response.topics.forEach(function (item) {
store1.add(item);
})
console.log(`total count of store1 data is ${store1.getCount()}`);
}
});
}
}
});

extjs subtable checkcolumn click

I am very new to extjs, and I saw this excellent post:
dynamic url inside a extjs table dont work
I was wondering if there is a way to enable checkbox functionality on the subtable?
I tried making slight modifications to the sample, but I can't find a way to have the checkboxes clickable and capture the events associated with it.
Please see the modified code below. Is it possible to have a clickable checkbox inside a Subtable?
Thanks in advance!
// SALVAGUARDAS -- added Approved field
Ext.define('Salvaguardas', {
extend: 'Ext.data.Model',
fields: ['Approved', 'id_amenaza', 'tipo', 'modo', 'codigo', 'denominacion', 'eficiencia', ]
});
//SALVAGUARDAS
var salvaguardaStore = Ext.create('Ext.data.Store', {
model: 'Salvaguardas',
data: [
{Approved: true, id_amenaza: 1, tipo: 'Correctiva', modo: 'Correctiva', codigo: 'corr-01', denominacion: 'correctiva 1', eficiencia: 'MB' }
]
});
//GRIDPANEL
Ext.create('Ext.grid.Panel', {
renderTo: 'example-grid',
store: amenazaStore,
//width: 748,
//height: 598,
title: '<bean:write name="informesAGRForm" property="nombreActivo"/>',
plugins: [{
ptype: "subtable",
headerWidth: 24,
listeners: {
'rowdblclick': function(grid, rowIndex, columnIndex, e){
// Get the Record, this is the point at which rowIndex references a
// record's index in the grid's store.
var record = grid.getStore().getAt(rowIndex);
// Get field name
var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
var data = record.get(fieldName);
alert(data);
}
},
columns: [{
//text: 'Approved',
//dataIndex: 'Approved',
//hidden: true,
//width: 100
xtype: 'checkcolumn',
header: 'Approved',
dataIndex: 'Approved',
width: 85,
listeners: {
checkChange: function ()
{
console.log('checkChange');
}
}
}, {
text: 'id_amenaza',
dataIndex: 'id_amenaza',
hidden: true,
width: 100
}, {
width: 100,
text: 'id_salvaguarda',
dataIndex: 'id_salvaguarda'
},
{
text: 'denominacion',
dataIndex: 'denominacion',
width: 100
},{
text: 'descripcion',
dataIndex: 'descripcion',
width: 100
},{
text: 'eficacia',
dataIndex: 'eficacia',
width: 100
},
],
getAssociatedRecords: function (record) {
var result = Ext.Array.filter(
salvaguardaStore.data.items,
function (r) {
return r.get('id_amenaza') == record.get('id');
});
return result;
}
}],
listeners: {
rowdblclick: function (view, record, tr, columnIndex, e) {
console.log('rowdblclick');
var cell = e.getTarget('.x-grid-subtable-cell');
if (!cell) {
return;
}
var row = Ext.get(cell).up('tr');
var tbody = row.up('tbody');
var rowIdx = tbody.query('tr', true).indexOf(row.dom);
//var records = view.up('grid').getPlugin('subtable').getAssociatedRecords(record);
var records = view.up('grid').plugins[0].getAssociatedRecords(record);
var subRecord = records[rowIdx];
console.log('rowdblclick: ' + rowIdx + ' - ' + subRecord);
},
rowclick: function (view, record, tr, columnIndex, e) {
console.log('rowclick');
var cell = e.getTarget('.x-grid-subtable-cell');
if (!cell) {
return;
}
var row = Ext.get(cell).up('tr');
var tbody = row.up('tbody');
var rowIdx = tbody.query('tr', true).indexOf(row.dom);
//var records = view.up('grid').getPlugin('subtable').getAssociatedRecords(record);
var records = view.up('grid').plugins[0].getAssociatedRecords(record);
var subRecord = records[rowIdx];
console.log('rowclick: ' + rowIdx + ' - ' + subRecord);
}
},
collapsible: false,
animCollapse: false,
columns: [
{
text: 'ID',
hidden: true,
hideable: false,
dataIndex: 'id'
},
{
text: 'Codigo',
width: 50,
sortable: true,
hideable: false,
dataIndex: 'codigo'
},
{
text: 'DenominaciĆ³n',
width: 150,
dataIndex: 'denominacion',
},
{
text: ' Autenticidad',
flex: 1,
dataIndex: 'a_riesgo'
},
{
text: 'Confidencialidad',
flex: 1,
dataIndex: 'c_riesgo'
},
{
text: 'Integridad',
flex: 1,
dataIndex: 'i_riesgo'
},
{
text: 'Disponibilidad',
flex: 1,
dataIndex: 'd_riesgo'
},
{
text: 'Trazabilidad',
flex: 1,
dataIndex: 't_riesgo'
},
{
text: 'Total',
flex: 1,
dataIndex: 'total_riesgo'
}]
});

Upgrading EXTJS 4.1 to 4.2... _incr_ is undefined in Ext.util.Observable

I'm having an issue where after upgrading from EXTJS 4.1 to 4.2, I'm getting the error: "Uncaught TypeError: undefined is not a function" which points to the ext-all.js addListener method for Ext.utilObservable. Specifically, when the _incr_ function is called, to increment the number of listeners:
addListener: function(ename, fn, scope, options) {
var me = this,
config, event,
prevListenerCount = 0;
if (typeof ename !== 'string') {
options = ename;
for (ename in options) {
if (options.hasOwnProperty(ename)) {
config = options[ename];
if (!me.eventOptionsRe.test(ename)) {
me.addListener(ename, config.fn || config, config.scope || options.scope, config.fn ? config : options);
}
}
}
if (options && options.destroyable) {
return new ListenerRemover(me, options);
}
}
else {
ename = ename.toLowerCase();
event = me.events[ename];
if (event && event.isEvent) {
prevListenerCount = event.listeners.length;
} else {
me.events[ename] = event = new ExtEvent(me, ename);
}
if (typeof fn === 'string') {
scope = scope || me;
fn = Ext.resolveMethod(fn, scope);
}
event.addListener(fn, scope, options);
if (event.listeners.length !== prevListenerCount) {
me.hasListeners._incr_(ename); // <----- right here
}
if (options && options.destroyable) {
return new ListenerRemover(me, ename, fn, scope, options);
}
}
},
I've attempted it replacing it with the method from EXTJS 4.1, but am finding more errors down the line. Is it possible that EXTJS isn't properly configured or is missing files?
EDIT the offending piece:
Ext.Loader.setConfig({
enabled: true
});
Ext.Loader.setPath('Ext.ux', '/_layouts/1033/scripts/perf/extjs/ux');
Ext.require([
'Ext.ux.grid.Printer',
// 'Ext.grid.plugin.BufferedRenderer'
// 'Ext.ux.grid.plugin.BufferedRenderer'
// 'Ext.ux.exporter.Exporter'
]);
Ext.onReady(function () {
Ext.QuickTips.init();
var myMask = new Ext.LoadMask('CostSummaryGrid', { msg: "Loading..." });
//debugger;
Ext.define('CostSummaryGrid', {
extend: 'Ext.data.Model',
fields: [{
name: 'WBSId',
type: 'int'
}, {
name: 'WBSName',
type: 'string'
}, {
name: 'EndDate',
type: 'string',
convert: function (value, record) {
if (value == null)
return null;
//debugger;
date = Ext.Date.parse(value, 'MS', true);
UTCdate = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
return Ext.Date.format(UTCdate, appConfig.DateFormat);
}
}, {
name: 'PlannedValue',
type: 'float'
}, {
name: 'EarnedValue',
type: 'float'
}, {
name: 'ActualCost',
type: 'float'
}, {
name: 'ScheduleVariance',
type: 'float'
}, {
name: 'CostVariance',
type: 'float'
}, {
name: 'CurrentBudget',
type: 'float'
}, {
name: 'EstimateAtCompletion',
type: 'float'
}, {
name: 'VarianceAtCompletion',
type: 'float'
}, {
name: 'SPI',
type: 'float'
}, {
name: 'CPI',
type: 'float'
}]
});
var costSummaryStore = Ext.create("Ext.data.Store", {
model: 'CostSummaryGrid',
autoLoad: false,
pageSize: 100,
proxy: {
type: 'ajax',
url: siteUrl + '_vti_bin/performanceportaldata.svc/GetCostSummaryGridFiltered',
noCache: false,
//extraParams: {wbsFilter: ''},
sortParam: undefined,
limitParam: undefined,
startParam: undefined,
pageParam: undefined,
headers: {
'Accept': 'application/json'
},
reader: {
type: 'json',
root: 'd'
}
},
storeId: 'CostSummaryStore',
wbsFilterable: true,
filterable: true,
startDateFilterable: false,
costSetFilterable: true,
wbsCostFilterable: true,
listeners: {
beforeload: function () {
myMask.show();
},
load: function () {
myMask.hide();
// grid.addDocked({ xtype: 'exporterbutton' }, 'top');
},
},
LoadIfReady: function() {
if (this.filterableReady === true && this.costSetFilterableReady === true
&& this.wbsCostFilterableReady === true && this.wbsFilterableReady === true) {
debugger;
this.load();
return true;
}
}
});
var grid = Ext.create('Ext.grid.Panel', {
store: costSummaryStore,
autoLoad: true,
plugins: {
ptype: 'bufferedrenderer',
trailingBufferZone: 50, // Keep 20 rows rendered in the table behind scroll
leadingBufferZone: 100 // Keep 50 rows rendered in the table ahead of scroll
},
features: [{
ftype: 'fixedsummary'
}],
tbar: [{
text: 'Print',
iconCls: 'icon-print',
handler : function(){
Ext.ux.grid.Printer.printAutomatically = false;
Ext.ux.grid.Printer.print(grid);
}
} //john wilson was here
],
showSummaryRow: false,
columns: [{
text: 'WBS Name',
flex: 3,
align: 'left',
sortable: true,
dataIndex: 'WBSName',
fixedSummaryType: 'count',
fixedSummaryRenderer: function (value, metadata, record) {
//return Ext.String.format('<em>Totals:</em>', value);
return value;
}
}, {
text: 'Planned Value',
flex: 2.1,
sortable: true,
align: 'center',
renderer: PerfPortal.Format.gridCurrencyNoDecimals,
dataIndex: 'PlannedValue',
fixedSummaryType: 'sum',
fixedSummaryRenderer: PerfPortal.Format.gridCurrencyNoDecimals
}, {
text: 'Earned Value',
flex: 2.1,
sortable: true,
align: 'center',
renderer: PerfPortal.Format.gridCurrencyNoDecimals,
dataIndex: 'EarnedValue',
fixedSummaryType: 'sum',
fixedSummaryRenderer: PerfPortal.Format.gridCurrencyNoDecimals
}, {
text: 'Actual Cost',
flex: 2.1,
sortable: true,
align: 'center',
renderer: PerfPortal.Format.gridCurrencyNoDecimals,
dataIndex: 'ActualCost',
fixedSummaryType: 'sum',
fixedSummaryRenderer: PerfPortal.Format.gridCurrencyNoDecimals
}, {
text: '<html>Schedule <br>Variance</html>',
flex: 2,
sortable: true,
align: 'center',
renderer: PerfPortal.Format.gridCurrencyNoDecimals,
dataIndex: 'ScheduleVariance',
fixedSummaryType: 'sum',
fixedSummaryRenderer: PerfPortal.Format.gridCurrencyNoDecimals
}, {
text: 'Cost Variance',
flex: 2,
sortable: true,
align: 'center',
renderer: PerfPortal.Format.gridCurrencyNoDecimals,
dataIndex: 'CostVariance',
fixedSummaryType: 'sum',
fixedSummaryRenderer: PerfPortal.Format.gridCurrencyNoDecimals
}, {
text: '<html>Budget at <br>Completion</html>',
flex: 2.3,
sortable: true,
align: 'center',
renderer: PerfPortal.Format.gridCurrencyNoDecimals,
dataIndex: 'CurrentBudget',
fixedSummaryType: 'sum',
fixedSummaryRenderer: PerfPortal.Format.gridCurrencyNoDecimals
}, {
text: '<html>Estimate at <br>Completion</html>',
flex: 2.3,
sortable: true,
align: 'center',
renderer: PerfPortal.Format.gridCurrencyNoDecimals,
dataIndex: 'EstimateAtCompletion',
fixedSummaryType: 'sum',
fixedSummaryRenderer: PerfPortal.Format.gridCurrencyNoDecimals
}, {
text: '<html>Variance at <br>Completion</html>',
flex: 2.3,
sortable: true,
align: 'center',
renderer: PerfPortal.Format.gridCurrencyNoDecimals,
dataIndex: 'VarianceAtCompletion',
fixedSummaryType: 'sum',
fixedSummaryRenderer: PerfPortal.Format.gridCurrencyNoDecimals
}, {
text: 'SPI',
flex: 1,
sortable: true,
align: 'center',
renderer: PerfPortal.Format.renderKPI,
dataIndex: 'SPI',
fixedSummaryType: 'sum',
fixedSummaryRenderer: function (val, meta, record, ri, ci, s, v) {
if (typeof (record) === 'undefined') {
return null;
}
var earnedValue = 0, planned = 0;
for (var i = 0; i < record.fields.length; i++) {
var fieldName = record.fields.items[i].name;
if (fieldName.lastIndexOf("EarnedValue", 0) === 0) {
earnedValue = record.get(fieldName);
}
if (fieldName.lastIndexOf("PlannedValue", 0) === 0) {
planned = record.get(fieldName);
}
}
var retVal = earnedValue / planned;
if (planned === 0) { retVal = 0; }
if (KPIStore.getById('SPI') != null) {
return PerfPortal.Format.renderKPIDirect(retVal, meta, 'SPI');
}
else
return retVal;
}
}, {
text: 'CPI',
flex: 1,
sortable: true,
align: 'center',
renderer: PerfPortal.Format.renderKPI,
dataIndex: 'CPI',
fixedSummaryType: 'sum',
fixedSummaryRenderer: function (val, meta, record, ri, ci, s, v) {
if (typeof (record) === 'undefined') {
return null;
}
var earnedValue = 0, actual = 0;
for (var i = 0; i < record.fields.length; i++) {
var fieldName = record.fields.items[i].name;
if (fieldName.lastIndexOf("ActualCost", 0) === 0) {
actual = record.get(fieldName);
}
if (fieldName.lastIndexOf("EarnedValue", 0) === 0) {
earnedValue = record.get(fieldName);
}
}
var retVal = earnedValue / actual;
if (actual === 0) { retVal = 0; }
if (KPIStore.getById('CPI') != null) {
return PerfPortal.Format.renderKPIDirect(retVal, meta, 'CPI');
}
else
return retVal;
//return Ext.util.Format.number(record.get('EarnedValue')/record.get('PlannedValue'),'0.00');
}
}],
height: 520,
width: 1000,
title: 'Cost Summary',
renderTo: 'CostSummaryGrid',
viewConfig: {
stripeRows: true,
loadMask: false
}
});
var summary = Ext.create('Ext.toolbar.Toolbar', {
dock: 'bottom',
//height: 25,
items: [{ xtype: 'displayfield'}]
});
var toolBar = Ext.create('Ext.toolbar.Toolbar', {
dock: 'bottom',
//height: 25,
items: [{ xtype: 'tbfill'}]
});
//var exportButton = Ext.create
grid.addDocked(toolBar);
var KPIStore = Ext.getStore('KPIStore');
if (KPIStore.isLoading()) {
KPIStore.on('load', function (store, records, options) {
addLegend(store, toolBar, 'CPI');
toolBar.insert('-');
addLegend(store, toolBar, 'SPI');
});
}
else {
addLegend(KPIStore, toolBar, 'CPI');
toolBar.insert('-');
addLegend(KPIStore, toolBar, 'SPI');
}
function addLegend(store, toolBar, type) {
var KPIdef = store.getById(type);
var poor = '<span style="margin-right: 5px; background-color: ' + KPIdef.data.Poor_color + '; color: ' + KPIdef.data.Poor_color + ';">__</span>' + KPIdef.data.Poor_label;
var caution = '<span style="margin-right: 5px; margin-left: 10px; background-color: ' + KPIdef.data.Caution_color + '; color: ' + KPIdef.data.Caution_color + ';">__</span>' + KPIdef.data.Caution_label;
var good = '<span style="margin-right: 5px; margin-left: 10px; background-color: ' + KPIdef.data.Good_color + '; color: ' + KPIdef.data.Good_color + ';">__</span>' + KPIdef.data.Good_label;
toolBar.insert({ xtype: 'tbtext',
padding: '5, 5, 5, 5',
text: KPIdef.data.Title + ': ' + poor + caution + good
}
);
}
});
With ExtJs 4.2, If a class has Events defined on it, it has to either extend Ext.util.Observable or add mixin of Ext.util.Observable. Also Observable's constructor must be called in this class's constructor like as following snippet,
Ext.define('Employee', {
// Change 1.....
extend: 'Ext.util.Observable',
constructor: function(config){
this.addEvents({
"sayHello" : true,
"sayGoodbye" : true
});
// Change 2.....
this.callParent(arguments)
}
});
OR
Ext.define('Employee', {
extend: 'Some other class',
// Change 1
mixins: {
observable: 'Ext.util.Observable'
},
constructor: function(config){
this.addEvents({
"sayHello" : true,
"sayGoodbye" : true
});
// Change 2.....
this.mixins.observable.constructor.call(this);
}
});

Concatenate in EditorGridPanel

Inside of my editorGridPanel, I have a three columns. I want to concatenate the data inside of my 'firstname' and 'lastname' column directly going to or when the cursor or focus are now in my 'email address' column in every row. Could someone help me about this problem?
var cm = new Ext.grid.ColumnModel({
defaults: {
sortable: true
},
columns: [{
id: 'id',
header: 'ID',
dataIndex: 'id',
width: 220,
editable: false,
hidden: true
},
{
id: 'firstname',
header: 'First Name',
dataIndex: 'firstname',
width: 220,
editor: new fm.TextField({
allowBlank: false
}),
listeners: {
click: function(){
Ext.getCmp('b_save').enable();
Ext.getCmp('b_cancel').enable();
}
}
},
{
id: 'lastname',
header: 'Last Name',
dataIndex: 'lastname',
width: 220,
align: 'left',
editor: new fm.TextField({
allowBlank: false
}),
listeners: {
click: function(){
Ext.getCmp('b_save').enable();
Ext.getCmp('b_cancel').enable();
}
}
},
{
id: 'email_address',
header: 'Email Address',
dataIndex: 'email_address',
width: 330,
align: 'left',
editor: new fm.TextField({
allowBlank: false
}),
listeners: {
click: function(){
Ext.getCmp('b_save').enable();
Ext.getCmp('b_cancel').enable();
}
}
},
var grid = new Ext.grid.EditorGridPanel({
viewConfig: {
forceFit: true,
autoFill: true
},
id: 'maingrid',
store: store,
cm: cm,
width: 700,
anchor: '100%',
height: 700,
frame: true,
loadMask: true,
waitMsg: 'Loading...',
clicksToEdit: 2,
sm : new Ext.grid.RowSelectionModel({
singleSelect: true
,onEditorKey : function(field, e) {
if (e.getKey() == e.ENTER) {
var k = e.getKey(), newCell, g = this.grid,ed = g.activeEditor || g.lastActiveEditor;
e.stopEvent();
/*ed.completeEdit();*/
if(e.shiftKey){
newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
}else{
newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
}
if(newCell){
g.startEditing(newCell[0], newCell[1]);
}
}
else if(e.getKey() == e.TAB){
var k = e.getKey(), newCell, g = this.grid,ed = g.activeEditor || g.lastActiveEditor;
e.stopEvent();
newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
if(newCell){
g.startEditing(newCell[0], newCell[1]);
}
}
}
}),
});
You can add concatenated firstname and lastname and set it as value into your email_address field in listener for beforeedit editorgrid event:
listeners: {
beforeedit: function(e) {
if (e.field === 'email_address' && e.value === '') {
var newValue = e.record.get('firstname') + '.' + e.record.get('lastname');
e.record.set('email_address', newValue);
}
}
},
Fiddle with example: https://fiddle.sencha.com/#fiddle/3mf

extjs: load mask grid

I am using extjs grid, and I have a jQuery timer, which will call RenderGrid function every 20 seconds. I want to show mask for grid each timer tick. Please advise.
function RenderGrid(dataObj) {
var jasonContent = JSON.parse(dataObj)
if (document.getElementById('panel').innerHTML != '') {
document.getElementById('panel').innerHTML = '';
}
var myData = {
records: jasonContent
};
var fields = [
{ name: 'Position_ID', mapping: 'Position_ID' },
{ name: 'PriorityCount', mapping: 'PriorityCount' },
{ name: 'MyCheckBox', mapping: 'MyCheckBox' },
{ name: 'Veh_Plateno', mapping: 'Veh_Plateno' },
{ name: 'Drv_Firstname', mapping: 'Drv_Firstname' },
{ name: 'GPSTimeAsString', mapping: 'GPSTimeAsString' },
{ name: 'Speed', mapping: 'Speed' },
{ name: 'SubFleet_Name', mapping: 'SubFleet_Name' }
];
var gridStore = new Ext.data.JsonStore({
fields: fields,
data: myData,
root: 'records'
});
var cols = [
{ id: 'Position_ID', header: "Position_ID", width: 160, sortable: true, dataIndex: 'Position_ID', hidden: true, hideable: false },
{ header: "", width: 30, sortable: false, dataIndex: 'MyCheckBox', renderer: renderCheckBox, hideable: false, menuDisabled: true },
{ header: "", width: 30, sortable: false, dataIndex: 'PriorityCount', renderer: renderIcon, hideable: false, menuDisabled: true },
{ header: "Veh_Plateno", width: 100, sortable: true, dataIndex: 'Veh_Plateno' },
{ header: "Drv_Firstname", width: 100, sortable: true, dataIndex: 'Drv_Firstname' },
{ header: "GPSTime", width: 100, sortable: true, dataIndex: 'GPSTimeAsString' },
{ header: "Speed", width: 100, sortable: true, dataIndex: 'Speed' },
{ header: "SubFleet_Name", width: 100, sortable: true, dataIndex: 'SubFleet_Name' }
];
gridStore.setDefaultSort('Veh_Plateno', 'asc');
var grid = new Ext.grid.GridPanel({
ddGroup: 'gridDDGroup',
store: gridStore,
renderTo: 'panel',
columns: cols,
enableDragDrop: true,
stripeRows: true,
pageSize:25,
header: false,
loadMask: true,
autoExpandColumn: 'Position_ID',
width: 900,
height: 325,
region: 'west',
title: 'Data Grid',
selModel: new Ext.grid.RowSelectionModel({ singleSelect: false }),
listeners: {
'rowdblclick': function (grid, rowIndex, e) {
var rec = grid.getStore().getAt(rowIndex);
var columnName = grid.getColumnModel().getDataIndex(2);
Ext.MessageBox.alert('', rec.get(columnName));
// do something
}
}
});
//grid.getEl().mask();
//grid.store.reload();
//grid.getEl().unmask();
//gridStore.load({ params: { start:0, limit: 25} });
/// grid.loadMask.show();
grid = null;
cols = null;
fields = null;
gridStore = null;
myData = null;
}
thaks man this approch working fine with me but now my browser is hanging it seems, grid object will enter in infinite loop this all my script code, please prvide me example with timer if you can :
var grid = null;
function RenderPositionsGrid(dataObj) {
var jasonContent = JSON.parse(dataObj)
var myData = {
records: jasonContent
};
if (grid == null) {
var fields = [
{ name: 'Position_ID', mapping: 'Position_ID' },
{ name: 'PriorityCount', mapping: 'PriorityCount' },
{ name: 'MyCheckBox', mapping: 'MyCheckBox' },
{ name: 'Veh_Plateno', mapping: 'Veh_Plateno' },
{ name: 'Drv_Firstname', mapping: 'Drv_Firstname' },
{ name: 'GPSTimeAsString', mapping: 'GPSTimeAsString' },
{ name: 'Speed', mapping: 'Speed' },
{ name: 'SubFleet_Name', mapping: 'SubFleet_Name' }
];
var gridStore = new Ext.data.JsonStore({
fields: fields,
data: myData,
root: 'records'
});
var cols = [
{ id: 'Position_ID', header: "Position_ID", width: 160, sortable: true, dataIndex: 'Position_ID', hidden: true, hideable: false },
{ header: "", width: 30, sortable: false, dataIndex: 'MyCheckBox', renderer: renderCheckBox, hideable: false, menuDisabled: true },
{ header: "", width: 30, sortable: false, dataIndex: 'PriorityCount', renderer: renderIcon, hideable: false, menuDisabled: true },
{ header: "Veh_Plateno", width: 100, sortable: true, dataIndex: 'Veh_Plateno' },
{ header: "Drv_Firstname", width: 100, sortable: true, dataIndex: 'Drv_Firstname' },
{ header: "GPSTime", width: 100, sortable: true, dataIndex: 'GPSTimeAsString' },
{ header: "Speed", width: 100, sortable: true, dataIndex: 'Speed' },
{ header: "SubFleet_Name", width: 100, sortable: true, dataIndex: 'SubFleet_Name' }
];
gridStore.setDefaultSort('Veh_Plateno', 'asc');
grid = new Ext.grid.GridPanel({
ddGroup: 'gridDDGroup',
store: gridStore,
renderTo: 'panel',
columns: cols,
enableDragDrop: true,
stripeRows: true,
pageSize: 25,
header: false,
loadMask: true,
autoExpandColumn: 'Position_ID',
width: 900,
height: 325,
region: 'west',
title: 'Data Grid',
selModel: new Ext.grid.RowSelectionModel({ singleSelect: false }),
listeners: {
'rowdblclick': function (grid, rowIndex, e) {
var rec = grid.getStore().getAt(rowIndex);
var columnName = grid.getColumnModel().getDataIndex(2);
Ext.MessageBox.alert('', rec.get(columnName));
// do something
}
}
});
}
else {
grid.store.loadData(myData);
}
}
function renderIcon(val) {
if (val) {
val = '../images/grid/icon_warning.png';
return "<img class=Blink src='" + val + "'>";
}
}
function renderCheckBox(val, cell, record) {
var x = '<input onclick="alert(' + cell.id + ')" type="checkbox" name="mycheckbox" />';
//var x = '<input type="checkbox" name="mycheckbox" />';
return x;
}
function renderDate(date) {
alert(date);
return date.format("d.m.Y");
}
function BindGridView() {
Data.GetVehiclePositions(onSuccess, onFail, null);
}
function onSuccess(result) {
RenderPositionsGrid(result);
var timeout = 4000; var timer;
timer = $.timer(timeout, function () { BindGridView(result); });
}
function onFail(result) {
alert("fail");
}
function blink() {
$('.Blink').delay(100).fadeTo(200, 0.5).delay(200).fadeTo(100, 1, blink);
}
Ext.onReady(function () {
BindGridView();
blink();
});
You could use
var myMask = new Ext.LoadMask(grid.getEl(), {msg:"Please wait..."});
myMask.show();
But I find your approach kind of weird, seems like the only thing changing every 20 seconds is your dada, your store, column model, grid never changed.
Can you just do a simple loadData(Object data, [Boolean append] ) in your timer handler? the API is here

Resources