Extjs paging toolbar: not able to set start - extjs

I having an issue with paging toolbar.
I want to give the user the option to set the no of results per page(limit). I have a drop-down for it.
I have initialised my page size as 20.
When i set my limit (e.g. 50) from dropdown, n suppose i get 90 results, so on the first page it is showing correctly from 1-50 results but on the next page its showing results from 21-70 instead of 51-90.
So i am not able to reset my page size according to limit set by the dropdown. the start is always picking up the initialised page size.
Any suggestions?
I am attaching my code...
linkCheckerUI = {
pageSize: 20,
test:null,
getPanel: function(config) {
var fields = ["path","jcrObject","type","URL","response"];
var rootpath = null;
var term= null;
var end=null;
var internal_links=null;
var external_links=null;
var smart_links=null;
var videoid_links=null;
this.store = new CQ.Ext.data.Store({
proxy: new CQ.Ext.data.HttpProxy({
url: '/bin/linkchecker',
method: 'GET'
}),
reader: new CQ.Ext.data.JsonReader({
"root": "data",
"fields": fields,
"idProperty":'jcrObject',
totalProperty: 'results'
}),
baseParams: { searchterm: term,startpath: rootpath, endpath: end,
internal: internal_links,external: external_links,smart: smart_links,videoid: videoid_links}
});
test=this.store;
this.store.on('beforeload',function(store, operation,eOpts){
limit= CQ.Ext.getCmp('limit').getRawValue();
limit = (limit=="") ? 15 : limit;
pageSize = limit;
start=operation.params.start;
start = (start==null) ? 0 : start;
searchterm = CQ.Ext.getCmp('searchterm').getValue();
startpath = CQ.Ext.getCmp('startpath').getValue();
endpath = CQ.Ext.getCmp('endpath').getValue();
internal = CQ.Ext.getCmp('internal').getValue();
external = CQ.Ext.getCmp('external').getValue();
smart = CQ.Ext.getCmp('smart').getValue();
videoid = CQ.Ext.getCmp('videoid').getValue();
ebroken = CQ.Ext.getCmp('excludebroken').getValue();
ehealthy= CQ.Ext.getCmp('excludehealthy').getValue();
alert(start);
operation.params={
searchterm: searchterm ,startpath: startpath , endpath: endpath ,
internal: internal ,external: external,smart: smart,videoid: videoid,start:start,
limit:limit,ebroken: ebroken,ehealthy: ehealthy
};},this);
this.loadGrid();
this.loadForm();
// create main panel
this.panel = new CQ.Ext.Panel({
region: 'center',
layout: 'border',
margins: '5 5 5 5',
height:'100%',
border: false,
items: [this.form,this.grid]
});
// load grid data
this.reload();
// return outer panel
return this.panel;
},
/**
* Load form
*/
loadForm: function() {
var searchterm = null;
this.form = new CQ.Ext.form.FormPanel({
region: "north",
title: "Link Control Center",
width: 220,
top: 50,
height:350,
collapsible: false,
split: true,
parent: this,
padding:'10px',
items: [
{
xtype: 'textfield',
name: 'searchterm',
id: 'searchterm',
fieldLabel:'Search Term',
emptyText:'Please enter a search term',
width: 583
},
{
xtype: 'pathfield',
name: 'startpath',
id: 'startpath',
fieldLabel: 'Start Path',
allowBlank: false,
width: 600
},
{
xtype: 'pathfield',
name: 'endpath',
id: 'endpath',
fieldLabel: 'End Path',
width: 600
},
{
xtype: 'combo',
name: 'limit',
id:'limit',
fieldLabel: 'Result Display',
emptyText:'Select # results per page',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
store: [['val1','15'],['val2','100'],['val3','500'],['val4','1000'],['val5','All']]
},
{
fieldLabel: 'Link Type',
xtype: 'checkbox',
boxLabel: 'Internal',
checked : true,
name: 'internal',
id:'internal'
},
{
xtype: 'checkbox',
boxLabel: 'External',
checked : true,
name: 'external',
id:'external'
},
{
xtype: 'checkbox',
boxLabel: 'SMART',
checked : true,
name: 'smart',
id:'smart'
},
{
xtype: 'checkbox',
boxLabel: 'Video (Asset ID)',
checked : true,
name: 'videoid',
id: 'videoid'
},
{
fieldLabel: 'Exclude',
xtype: 'checkbox',
boxLabel: 'Exclude broken links',
name: 'excludebroken',
id:'excludebroken'
},
{
xtype: 'checkbox',
boxLabel: 'Exclude healthy links',
name: 'excludehealthy',
id: 'excludehealthy'
}
],
buttons:[{
text: 'Submit',
handler: function() {
searchterm = CQ.Ext.getCmp('searchterm').getValue();
startpath = CQ.Ext.getCmp('startpath').getValue();
endpath = CQ.Ext.getCmp('endpath').getValue();
internal = CQ.Ext.getCmp('internal').getValue();
external = CQ.Ext.getCmp('external').getValue();
smart = CQ.Ext.getCmp('smart').getValue();
videoid = CQ.Ext.getCmp('videoid').getValue();
limit = CQ.Ext.getCmp('limit').getRawValue();
pageSize=15;
alert("2");
test.clearFilter(false);
if(startpath){
if (endpath.substring(0, startpath.length) == startpath || endpath=="")
{
test.load();
}
else
{
alert('Specified End Path is not within Start Path node!\nSelect an End Path within and below Start Path hierarchy node');
}
}
else{
alert('Fill in all required fields before submitting the query');
}
}
}
]
});
},
/**
* Load grid
*/
loadGrid: function() {
// export to CSV button
this.exportCSVButton = new CQ.Ext.Button({iconCls: 'icon-csv', text: 'Export as CSV'});
this.exportCSVButton.setHandler(function() {
searchterm = CQ.Ext.getCmp('searchterm').getValue();
startpath = CQ.Ext.getCmp('startpath').getValue();
endpath = CQ.Ext.getCmp('endpath').getValue();
internal = CQ.Ext.getCmp('internal').getValue();
external = CQ.Ext.getCmp('external').getValue();
smart = CQ.Ext.getCmp('smart').getValue();
videoid = CQ.Ext.getCmp('videoid').getValue();
ebroken = CQ.Ext.getCmp('excludebroken').getValue();
ehealthy= CQ.Ext.getCmp('excludehealthy').getValue();
var url = "/bin/linkchecker.csv?searchterm="+searchterm +"&startpath="+startpath +"&endpath="+endpath+ "&internal="+internal +"&external="+external+
"&smart="+smart+"&videoid"+videoid+"&ebroken="+ebroken +"&ehealthy="+ehealthy+"&start=0&limit=-1" ;
window.location=(url);
}, this);
var body = CQ.Ext.getBody();
this.grid = new CQ.Ext.grid.GridPanel({
region: "center",
border:false,
store: this.store,
//parent:this,
loadMask: new CQ.Ext.LoadMask(body, {msg: 'Loading please wait...'}),
tbar: ['Result List',
'->', this.exportCSVButton
],
columns: [
{header: "Path", width: 80,dataIndex: 'path', sortable: true},
{header: "JCR Object Node", width: 80,dataIndex: 'jcrObject', sortable: true},
{header: "Type", width: 15, dataIndex: 'type', sortable: true},
{header: "URL", width: 70, dataIndex: 'URL', sortable: true},
{header: "Error Type", width:15, dataIndex: 'response', sortable: true,
renderer: function(value){ if (value =='200')return '<span style="color:green;">'+value+'</span>'; else return '<span style="color:red;">'+value+'</span>';}}
],
renderTo:this.grid,
stripeRows: true,
viewConfig: {
forceFit: true
},
bbar: new CQ.Ext.PagingToolbar({
store: this.store,
pageSize:this.pageSize,
displayInfo: true
}),
sm: new CQ.Ext.grid.RowSelectionModel({singleSelect:true}),
iconCls:'icon-grid'
});
alert("3");
this.grid.loadMask.show();
},
/**
* Reload grid data (reset to first page)
*/
reload: function() {
alert("4");
this.store.load({ baseParams: {start: 0, limit: this.pageSize}});
}
}

Try using extraParams on the store.
this.store.getProxy().extraParams = { start: 0, limit: this.pageSize};
this.store.load();

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()}`);
}
});
}
}
});

how to use bufferedrenderer instead of paging toolbar in extjs

{ extend: 'Ext.grid.Panel',
autoScroll: true,
layout: 'fit',
padding: '5 5 5 0',
width: 450,
selModel: {
mode: 'MULTI',
pruneRemoved: false
},
config: {
labels: {},
defSel: {},
keepSelections: true
},
initComponent: function() {
this.title = this.labels.MEAS_LIST_PANEL_TITLE;
var measStore = Optima.store.Measurement.create();
this.store = measStore;
this.columns = [{
text: 'list',
sortable: true,
dataIndex: 'name',
flex: 1
}, {
text: 'unit'
sortable: true,
dataIndex: 'unit',
flex: 1
}, {
text: 'sample'
sortable: true,
dataIndex: 'sampletime',
flex: 1
}, {
text: 'desc',
sortable: true,
id: 'desc',
dataIndex: 'desc',
flex: 1
}];
this.bbar = {
xtype: 'pagingtoolbar',
pageSize: 25,
store: measStore,
displayInfo: false
};
this.callParent(arguments);
}
});
You should use the buffered store.
Ext.create('Ext.data.BufferedStore', {
storeId: 'exampleStore',
autoLoad : true,
pageSize : 100,
fields: ['userId', 'id', 'title'],
proxy : {
type : 'ajax',
...
}
});
Then get rid of the paging toolbar since the buffered store will automatically page based off page size.
A BufferedStore maintains a sparsely populated map of pages corresponding to an extremely large server-side dataset.
For more details you can refer ExtJS Docs for BufferedStore
I have created an sencha fiddle demo this will show how it is working.
Ext.define('ForumThread', {//Define model
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'
});
// create the Data Store
var store = Ext.create('Ext.data.BufferedStore', {
model: 'ForumThread',
remoteGroup: true,
leadingBufferZone: 300,
pageSize: 50,
proxy: {
// load using script tags for cross domain, if the data in on the same domain as
// this page, an Ajax proxy would be better
type: 'jsonp',
url: 'https://www.sencha.com/forum/remote_topics/index.php',
reader: {
rootProperty: 'topics',
totalProperty: 'totalCount'
},
// sends single sort as multi parameter
simpleSortMode: true,
// sends single group as multi parameter
simpleGroupMode: true,
// This particular service cannot sort on more than one field, so grouping === sorting.
groupParam: 'sort',
groupDirectionParam: 'dir'
},
sorters: [{
property: 'threadid',
direction: 'ASC'
}],
autoLoad: true,
listeners: {
// This particular service cannot sort on more than one field, so if grouped, disable sorting
groupchange: function (store, groupers) {
var sortable = !store.isGrouped(),
headers = grid.headerCt.getVisibleGridColumns(),
i, len = headers.length;
for (i = 0; i < len; i++) {
headers[i].sortable = (headers[i].sortable !== undefined) ? headers[i].sortable : sortable;
}
},
// This particular service cannot sort on more than one field, so if grouped, disable sorting
beforeprefetch: function (store, operation) {
if (operation.getGrouper()) {
operation.setSorters(null);
}
}
}
});
function renderTopic(value, p, record) {
return Ext.String.format(
'{0}',
value,
record.data.forumtitle,
record.getId(),
record.data.forumid
);
}
var grid = Ext.create('Ext.grid.Panel', {
width: '100%',
height: 500,
collapsible: true,
title: 'Buffer grid example with buffer store',
store: store,
loadMask: true,
selModel: {
pruneRemoved: false
},
viewConfig: {
trackOver: false
},
features: [{
ftype: 'grouping',
hideGroupedHeader: false
}],
columns: [{
xtype: 'rownumberer',
width: 50,
sortable: false
}, {
tdCls: 'x-grid-cell-topic',
text: "Topic",
dataIndex: 'title',
flex: 1,
renderer: renderTopic,
sortable: true,
groupable: false,
cellWrap: true,
filter: true
}, {
text: "Author",
dataIndex: 'username',
width: 100,
hidden: true,
sortable: true,
groupable: false
}, {
text: "Replies",
dataIndex: 'replycount',
align: 'center',
width: 70,
sortable: false,
filter: {
type: 'numeric'
}
}, {
id: 'last',
text: "Last Post",
dataIndex: 'lastpost',
width: 130,
renderer: Ext.util.Format.dateRenderer('d-M-Y h:i A'),
sortable: true,
groupable: false
}],
renderTo: Ext.getBody()
});

How to send date in format Y-m-d Ext JS 6

I have a grid. When I add new row script automatically puts there date in format "Y-m-d" and its work fine, Ext JS automatically sends to server date in format "2017-06-24" ("Y-m-d"). But when I update this date, Ext JS send to server date in format 2017-06-24T00:00:00.
Whats wrong?
Help me send to server "2017-06-24" date ("Y-m-d"), after updating.
Ext.require(['Ext.data.*', 'Ext.grid.*']);
// Создаем model
Ext.define('Users', {
extend: 'Ext.data.Model',
//idProperty: 'id',
fields: [{
name: 'id',
type: 'int'
}
]
});
Ext.onReady(function() {
// Создаем store
var store = Ext.create('Ext.data.Store', {
autoLoad: true,
autoSync: true,
model: 'Users',
proxy: {
type: 'ajax',
url: 'server.php',
api: {
create: 'server.php?action=create',
read: 'server.php?action=read',
update: 'server.php?action=update',
destroy: 'server.php?action=delete'
},
reader: {
type: 'json',
rootProperty: 'data'
},
writer: {
type: 'json',
encode: true,
rootProperty: 'dataUpdate',
allowSingle: false,
writeAllFields: true,
//root:'records'
},
actionMethods: {
create: 'GET',
read: 'GET',
update: 'GET',
destroy: 'GET'
}
},
listeners: {
write: function(store, operation) {
var record = operation.getRecords()[0],
name = Ext.String.capitalize(operation.action),
verb;
if (name == 'Destroy') {
verb = 'Destroyed';
} else {
verb = name + 'd';
}
//Ext.example.msg(name, Ext.String.format("{0} user: {1}", verb, record.getId()));
}
}
}
);
var grid = Ext.create('Ext.grid.Panel', {
renderTo: document.body,
//plugins: [rowEditing],
// Редактирование
plugins: {
ptype: 'cellediting',
clicksToEdit: 1
},
listeners: {
edit: function() {
}
},
width: 1000,
height: 330,
frame: true,
title: 'Users',
store: store,
iconCls: 'icon-user',
columns: [{
text: 'id',
width: 50,
sortable: true,
dataIndex: 'id',
renderer: function(v, meta, rec) {
return rec.phantom ? '' : v;
}
},
{
header: 'Дата',
width: 70,
// sortable: true,
dataIndex: 'date',
renderer: Ext.util.Format.dateRenderer('d/m/Y'),
editor: {
completeOnEnter: false,
field: {
xtype: 'datefield',
dateFormat: 'd/m/Y',
allowBlank: false
}
}
},
{
header: 'Время начала',
width: 120,
// sortable: true,
dataIndex: 'time_start',
//format: 'H:i',
// Нужно для верного отображеия времени после редактирования в таблице
renderer: Ext.util.Format.dateRenderer('H:i'),
editor: {
completeOnEnter: false,
field: {
xtype: 'timefield',
format: 'H:i',
//name: 'timeStart1',
//fieldLabel: 'Time In',
minValue: '8:00',
maxValue: '20:00',
increment: 30,
anchor: '100%',
allowBlank: false
}
}
}
],
dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'Add',
iconCls: 'icon-add',
handler: function() {
// Создаем новую задачу
// Для корректной работы с БД нужно задать ID новой строки, равной +1 от последней ID из таблицы.
var rec = new Users();
//console.log (x);("rec data= " + rec.id + " -- " + rec.data.id);
var idArr = grid.store.data.items;
var idValue = [];
for (var i = 0; i < idArr.length; i++) {
idValue.push(idArr[i].id);
}
idValue.sort(function(a, b) {
return a - b;
});
var maxId = idValue[idValue.length - 1];
console.log(maxId);
rec.id = maxId + 1;
rec.data.id = maxId + 1;
rec.date = Ext.Date.format(new Date(), 'Y-m-d');
rec.data.date = Ext.Date.format(new Date(), 'Y-m-d');
rec.time_start = Ext.Date.format(new Date(), '2008-01-01\\TH:i:s');
rec.data.time_start = Ext.Date.format(new Date(), '2008-01-01\\TH:i:s');
store.insert(0, rec);
//store.add(rac);
//grid.getView().refresh();
// rowEditing.startEdit(rec, 0);
}
}, '-', {
itemId: 'delete',
text: 'Delete',
iconCls: 'icon-delete',
disabled: false,
handler: function() {
var selection = grid.getView().getSelectionModel().getSelection()[0];
if (confirm('Вы действительно хотите удалить задачу №' + selection.id + " ?")) {
// Удлаяем
if (selection) {
store.remove(selection);
}
}
}
}]
}]
});
});
The datefield xtype has a submitFormat config where you can specify the date format string to be submitted to the server.
https://docs.sencha.com/extjs/6.2.0/classic/Ext.form.field.Date.html#cfg-submitFormat
Update: As Selmaril mentioned in the comment, this goes into the section where you define a datefield.
{
header: 'Дата',
width: 70,
// sortable: true,
dataIndex: 'date',
renderer: Ext.util.Format.dateRenderer('d/m/Y'),
editor: {
completeOnEnter: false,
field: {
xtype: 'datefield',
dateFormat: 'd/m/Y',
submitFormat: 'd/m/Y'
allowBlank: false
}
}
}
You are working with a Model here. On that model, you have a fields config where you can define which fields contain which data ype, and in case of date, in which format it should be submitted to the server.
fields:[{
name: 'id',
type: 'int'
},{
name: 'date',
type:'date',
dateFormat:'Y-m-d'
}]
Furthermore, I see some other red flags in your code:
Don't use record.date = or record.data.date = to set the date on the record.
Don't format the date using Date.format() unless absolutely necessary. Internally, you should always work with javascript dates, not strings. Use a xtype:'gridcolumn' in your grid with the appropriate format (e.g. format:'d/m/Y') for display.
So, for instance, when programmatically updating an existing record or creating a new grid row or a new record outside store, use record.set('date', new Date()); or store.add({date:new Date()}) or Ext.create('Users',{date: new Date()}).
I use dateWriteFormat: "Y-m-d" in my models and it works perfectly to send US-classic dates to my postgres backend.

Checkboxgroup getting duplicates value on second call

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
});

How to edit cell in grid panel in Ext JS 3.4?

Is it possible to make cell editable in ext js 3.4 gridpanel?
If yes please reply me how?
This is the code I tried,
var fm = Ext.form;
var grid = new Ext.grid.EditorGridPanel({
height: 500,
renderTo: Ext.getBody(),
width: 800,
loadMask: false,
viewConfig: {
emptyText: 'No data to display'
},
selModel: checkboxselection,
tbar: mainGridToolbar,
clicksToEdit: 1,
store: cartStore,
listeners: {
afteredit: function(o) {
var pos = o.record.get('POS');
var quantity = o.value;
}
},
columns: [
checkboxselection,
{
header: "quantity",
align: 'right',
dataIndex: 'QUANTITY',
sortable: true,
editor: new fm.TextField({
allowBlank: false
})
}
]
});
Edit
You are missing the plugin line... (I never heard of a EditorGridPanel, but I am on 4.x and may be mistaken at this point)
plugins: new Ext.ux.grid.RowEditor({saveText: 'Update'});
Origin
Use the Row Editor Plugin for these. You can specify for each cell if it should be editable or not.
You should really take look at the examples that comes along with the library! These lines can be found under ext-3.4.0\examples\grid\row-editor.js
Ext.onReady(function(){
Ext.QuickTips.init();
var Employee = Ext.data.Record.create([{
name: 'name',
type: 'string'
}, {
name: 'email',
type: 'string'
}, {
name: 'start',
type: 'date',
dateFormat: 'n/j/Y'
},{
name: 'salary',
type: 'float'
},{
name: 'active',
type: 'bool'
}]);
// hideous function to generate employee data
var genData = function(){
var data = [];
var s = new Date(2007, 0, 1);
var now = new Date(), i = -1;
while(s.getTime() < now.getTime()){
var ecount = Ext.ux.getRandomInt(0, 3);
for(var i = 0; i < ecount; i++){
var name = Ext.ux.generateName();
data.push({
start : s.clearTime(true).add(Date.DAY, Ext.ux.getRandomInt(0, 27)),
name : name,
email: name.toLowerCase().replace(' ', '.') + '#exttest.com',
active: true,
salary: Math.floor(Ext.ux.getRandomInt(35000, 85000)/1000)*1000
});
}
s = s.add(Date.MONTH, 1);
}
return data;
}
var store = new Ext.data.GroupingStore({
reader: new Ext.data.JsonReader({fields: Employee}),
data: genData(),
sortInfo: {field: 'start', direction: 'ASC'}
});
var editor = new Ext.ux.grid.RowEditor({
saveText: 'Update'
});
var grid = new Ext.grid.GridPanel({
store: store,
width: 600,
region:'center',
margins: '0 5 5 5',
autoExpandColumn: 'name',
plugins: [editor],
view: new Ext.grid.GroupingView({
markDirty: false
}),
tbar: [{
iconCls: 'icon-user-add',
text: 'Add Employee',
handler: function(){
var e = new Employee({
name: 'New Guy',
email: 'new#exttest.com',
start: (new Date()).clearTime(),
salary: 50000,
active: true
});
editor.stopEditing();
store.insert(0, e);
grid.getView().refresh();
grid.getSelectionModel().selectRow(0);
editor.startEditing(0);
}
},{
ref: '../removeBtn',
iconCls: 'icon-user-delete',
text: 'Remove Employee',
disabled: true,
handler: function(){
editor.stopEditing();
var s = grid.getSelectionModel().getSelections();
for(var i = 0, r; r = s[i]; i++){
store.remove(r);
}
}
}],
columns: [
new Ext.grid.RowNumberer(),
{
id: 'name',
header: 'First Name',
dataIndex: 'name',
width: 220,
sortable: true,
editor: {
xtype: 'textfield',
allowBlank: false
}
},{
header: 'Email',
dataIndex: 'email',
width: 150,
sortable: true,
editor: {
xtype: 'textfield',
allowBlank: false,
vtype: 'email'
}
},{
xtype: 'datecolumn',
header: 'Start Date',
dataIndex: 'start',
format: 'm/d/Y',
width: 100,
sortable: true,
groupRenderer: Ext.util.Format.dateRenderer('M y'),
editor: {
xtype: 'datefield',
allowBlank: false,
minValue: '01/01/2006',
minText: 'Can\'t have a start date before the company existed!',
maxValue: (new Date()).format('m/d/Y')
}
},{
xtype: 'numbercolumn',
header: 'Salary',
dataIndex: 'salary',
format: '$0,0.00',
width: 100,
sortable: true,
editor: {
xtype: 'numberfield',
allowBlank: false,
minValue: 1,
maxValue: 150000
}
},{
xtype: 'booleancolumn',
header: 'Active',
dataIndex: 'active',
align: 'center',
width: 50,
trueText: 'Yes',
falseText: 'No',
editor: {
xtype: 'checkbox'
}
}]
});
var cstore = new Ext.data.JsonStore({
fields:['month', 'employees', 'salary'],
data:[],
refreshData: function(){
var o = {}, data = [];
var s = new Date(2007, 0, 1);
var now = new Date(), i = -1;
while(s.getTime() < now.getTime()){
var m = {
month: s.format('M y'),
employees: 0,
salary: 0,
index: ++i
}
data.push(m);
o[m.month] = m;
s = s.add(Date.MONTH, 1);
}
store.each(function(r){
var m = o[r.data.start.format('M y')];
for(var i = m.index, mo; mo = data[i]; i++){
mo.employees += 10000;
mo.salary += r.data.salary;
}
});
this.loadData(data);
}
});
cstore.refreshData();
store.on('add', cstore.refreshData, cstore);
store.on('remove', cstore.refreshData, cstore);
store.on('update', cstore.refreshData, cstore);
var chart = new Ext.Panel({
width:600,
height:200,
layout:'fit',
margins: '5 5 0',
region: 'north',
split: true,
minHeight: 100,
maxHeight: 500,
items: {
xtype: 'columnchart',
store: cstore,
url:'../../resources/charts.swf',
xField: 'month',
yAxis: new Ext.chart.NumericAxis({
displayName: 'Employees',
labelRenderer : Ext.util.Format.numberRenderer('0,0')
}),
tipRenderer : function(chart, record, index, series){
if(series.yField == 'salary'){
return Ext.util.Format.number(record.data.salary, '$0,0') + ' total salary in ' + record.data.month;
}else{
return Ext.util.Format.number(Math.floor(record.data.employees/10000), '0,0') + ' total employees in ' + record.data.month;
}
},
// style chart so it looks pretty
chartStyle: {
padding: 10,
animationEnabled: true,
font: {
name: 'Tahoma',
color: 0x444444,
size: 11
},
dataTip: {
padding: 5,
border: {
color: 0x99bbe8,
size:1
},
background: {
color: 0xDAE7F6,
alpha: .9
},
font: {
name: 'Tahoma',
color: 0x15428B,
size: 10,
bold: true
}
},
xAxis: {
color: 0x69aBc8,
majorTicks: {color: 0x69aBc8, length: 4},
minorTicks: {color: 0x69aBc8, length: 2},
majorGridLines: {size: 1, color: 0xeeeeee}
},
yAxis: {
color: 0x69aBc8,
majorTicks: {color: 0x69aBc8, length: 4},
minorTicks: {color: 0x69aBc8, length: 2},
majorGridLines: {size: 1, color: 0xdfe8f6}
}
},
series: [{
type: 'column',
displayName: 'Salary',
yField: 'salary',
style: {
image:'../chart/bar.gif',
mode: 'stretch',
color:0x99BBE8
}
}]
}
});
var layout = new Ext.Panel({
title: 'Employee Salary by Month',
layout: 'border',
layoutConfig: {
columns: 1
},
width:600,
height: 600,
items: [chart, grid]
});
layout.render(Ext.getBody());
grid.getSelectionModel().on('selectionchange', function(sm){
grid.removeBtn.setDisabled(sm.getCount() < 1);
});
});

Resources