EXTJS4- pagination is not proper in the grid - extjs

I have set the pagesize in store and totalproperty in proxy setting and also defined dockedItems config. But in the page, all the records are displayed, instead of specified pagesize. Here is my code:
js file:
var sm = Ext.create('Ext.selection.CheckboxModel');
Ext.define('SuperUser', {
extend: 'Ext.data.Model',
fields: [
{ name: 'fname', type: 'string' },
{ name: 'lname', type: 'string' },
{ name: 'email', type: 'string' },
{ name: 'uid', type: 'string' },
{ name: 'isSup', type: 'boolean' },
{ name: 'upDate', type: 'string' },
{ name: 'upBy', type: 'string' }
]
});
//Create the grid
var superGrid=Ext.define('supusergrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.supusergrid',
title: 'Super Admin Grid',
gridId:'grid',
model:'SuperUser',
store: Ext.create('Ext.data.Store', {
storeId: 'supUserStore',
pageSize: 3,
model:'SuperUser',
autoLoad: true,
proxy: {
type: 'ajax',
url : 'supUserStore.json',
reader: {
type: 'json',
root: 'data',
totalProperty:'total'
}
}
}),
selModel: sm,
columns: [
{
header: 'First Name',
dataIndex: 'fname'
},
{
header: 'Last Name',
dataIndex: 'lname'
},
{
header: 'Email',
dataIndex: 'email'
},
{
header: 'User ID',
dataIndex: 'uid'
},
{
header: 'Super Admin',
dataIndex: 'isSup'
},
{
header: 'Updated Date',
dataIndex: 'upDate',
},
{
header: 'Updated By',
dataIndex: 'upBy'
}
],
dockedItems: [{
xtype: 'pagingtoolbar',
store: Ext.data.StoreManager.lookup('supUserStore'),
dock: 'bottom',
displayInfo: true
}],
initComponent: function () {
this.callParent(arguments);
}
});
Ext.onReady(function () {
Ext.widget('supusergrid', {
renderTo: 'div1'
});
});
json file:
{
"success": true,
"total": 12,
"data": [
{ "fname": "Jane","lname":"Smith","email": "j.smith#netapp.com", "uid": "jsmith","isSup":false,"upDate":"11-19-2012","upBy":"aaron#netapp.com" },
{ "fname": "Jim","lname":"Smith","email": "jm.smith#netapp.com", "uid": "jmsmith","isSup":true,"upDate":"11-23-2012","upBy":"aaron#netapp.com" },
{ "fname": "Jane","lname":"Smith","email": "j.smith#netapp.com", "uid": "jsmith","isSup":false,"upDate":"11-19-2012","upBy":"aaron#netapp.com" },
{ "fname": "Jim","lname":"Smith","email": "jm.smith#netapp.com", "uid": "jmsmith","isSup":true,"upDate":"11-23-2012","upBy":"aaron#netapp.com" },
{ "fname": "Jane","lname":"Smith","email": "j.smith#netapp.com", "uid": "jsmith","isSup":false,"upDate":"11-19-2012","upBy":"aaron#netapp.com" },
{ "fname": "Jim","lname":"Smith","email": "jm.smith#netapp.com", "uid": "jmsmith","isSup":true,"upDate":"11-23-2012","upBy":"aaron#netapp.com" },
{ "fname": "Jane","lname":"Smith","email": "j.smith#netapp.com", "uid": "jsmith","isSup":false,"upDate":"11-19-2012","upBy":"aaron#netapp.com" },
{ "fname": "Jim","lname":"Smith","email": "jm.smith#netapp.com", "uid": "jmsmith","isSup":true,"upDate":"11-23-2012","upBy":"aaron#netapp.com" },
{ "fname": "Jane","lname":"Smith","email": "j.smith#netapp.com", "uid": "jsmith","isSup":false,"upDate":"11-19-2012","upBy":"aaron#netapp.com" },
{ "fname": "Jim","lname":"Smith","email": "jm.smith#netapp.com", "uid": "jmsmith","isSup":true,"upDate":"11-23-2012","upBy":"aaron#netapp.com"}
]
}
please suggest, where I am going wrong.

You are using an Ajax proxy. On your server, you can intercept request parameters page, start and limit. Then you create a json response with the page data.

Store paging isn't as smart as you seem to think it is. Just because you tell it that the page size is 3 records and that you have 12 total records doesn't mean it's going to break everything up into 4 nice pages for you.
When calling store.loadPage the store adds the start and limit params to the proxy request. When the response comes back, it assumes that you've correctly limited your result set and loads all records provided. It is your responsibility to use those params to limit the results returned to the store. Usually, this would require posting the data on a server so you can utilize these params.
Thankfully, there's a UX component that should help you out: Ext.ux.data.PagingMemoryProxy
And here's some sample code showing how it works: Sliding Pager example

Related

Extjs store.load not working

I'm getting from php an json encoded
{
"employees": [{
"Employee_ID": "1",
"Department_ID": "2",
"Name": "Bagio",
"Email": "bagio#gmail.com"
}, {
"Employee_ID": "2",
"Department_ID": "2",
"Name": "Sinchan",
"Email": "sinchan#gmail.com"
}]
}
When I try to load it I get no response. This is my ExtJs 4.2 code
Ext.onReady(function() {
Ext.define('Person', {
extend: 'Ext.data.Model',
fields: [
'Employee_ID', 'Department_ID', 'Name', 'Email'
]
});
// create the Data Store
var store = Ext.create('Ext.data.Store', {
model: 'Person',
autoLoad: true,
proxy: {
type: 'memory',
url: 'example.php',
reader: {
type: 'json',
root: 'employees'
}
}
});
store.load();
Ext.create('Ext.grid.Panel', {
store: store,
columns: [{
text: "Employ_id",
width: 120,
dataIndex: 'Employee_ID'
},
{
text: "Department_ID",
width: 380,
dataIndex: 'Department_ID'
},
{
text: "Name",
width: 380,
dataIndex: 'Name'
},
{
text: "Email",
width: 380,
dataIndex: 'Email'
}
],
renderTo: 'example-grid',
width: 500,
height: 280
});
});
Try changing the store's proxy type from memory to ajax. Memory proxy usually is for data that will be loaded from the client session itself, not from a remote source.

How to load the values in combobox from database

How do I populate combo box values instead of hard coding from the database into the store of combo box
{
xtype: 'fieldset',
title: 'Dress Types',
items: [
{
xtype: 'combobox',
displayField: "displayName",
valueField: "displayName",
emptyText: 'Select Type',
store: {
fields: ["id", "displayName"],
data: [
{ "id": "1", "displayName": "Kurtha" },
{ "id": "2", "displayName": "Denim Top" },
{ "id": "3", "displayName": "Western T shirt" },
{ "id": "4", "displayName": "Sleeveless" }
]
},
name: 'dresses',
margin: '15px',
allowBlank: false,
forceSelection: true,
}
]
}
Thanks in advance
There are ways by which you can get this. You need to create one store in your js from your input data and then assign it to the comboBox.
Given example
var combstore = Ext.create('Ext.data.Store', {
autoLoad: true,
fields: [{
name: 'value',
mapping: "ITEMID",
type: 'string'
}, {
name: 'name',
mapping: "TITLE",
type: 'string'
}],
proxy: new Ext.data.HttpProxy({
type: 'ajax',
actionMethods: {
read: "POST"
},
url: Your URL,
headers: {
'Accept': 'application/json; charset=utf-8'
},
reader: {
type: 'json',
rootProperty: 'data'
},
autoLoad: true
})
});
Now in your comboBox you can call this combstore to your store.
store :combstore
In the variable combostore we are creating one data store by using Ext.data.Store and placing values in field. Then in proxy method calling url and mapping the values from field.
Read the doc for better understanding Doc
Check the below code.
Ext.create('Ext.form.ComboBox', {
valueField: "displayName",
emptyText: 'Select Type',
store: Ext.create('Ext.data.Store', {
fields: ["id", "displayName"],
proxy: {
url: 'data1.json',
reader: {
type: 'json',
rootProperty: 'data'
}
},
autoLoad: true
}),
name: 'dresses',
margin: '15px',
allowBlank: false,
forceSelection: true,
renderTo: Ext.getBody()
});
I assumed my service returing data like below
{
"data": [{
"id": "1",
"displayName": "Kurtha"
}, {
"id": "2",
"displayName": "Denim Top"
}, {
"id": "3",
"displayName": "Western T shirt"
}, {
"id": "4",
"displayName": "Sleeveless"
}]
}

How to combine rowediting and rowexpander together correctly in extjs?

I am developing a web application in ExtJS. The application is a grid where some of the grid`s rows can be expanded to show supplementary information as a nested grid. And user can edit rows in parent grid.
But I have problems with it. The nested grid is normally rendered , but when I want to update one of the field nested grid disappear.
There is testing version of my application and some screenshots.
The Code ( below you can find screens)
Ext.onReady(function() {
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: {
'items': [{
'name': 'Lisa',
"email": "lisa#simpsons.com",
"phone": "555-111-1224"
},
{
'name': 'Bart',
"email": "bart#simpsons.com",
"phone": "555-222-1234"
},
{
'name': 'Homer',
"email": "home#simpsons.com",
"phone": "555-222-1244"
},
{
'name': 'Marge',
"email": "marge#simpsons.com",
"phone": "555-222-1254"
}
]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
plugins: [{
ptype: 'rowexpander',
pluginId: 'courseListGridExpander',
expandOnDblClick: false,
selectRowOnExpand: false,
enableCaching: false,
rowBodyTpl: ['']
},
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 2,
autoCancel: false
})
],
viewConfig: {
listeners: {
expandbody: function(rowNode, record, expandbody) {
var targetId = 'SessionInstructionGridRow';
if (Ext.getCmp(targetId + "_grid") == null) {
var sessionInstructionGrid = Ext.create('Ext.grid.Panel', {
renderTo: targetId,
id: targetId + "_grid",
title: 'Nested One',
columns: [{
header: 'Halo',
flex: 1
},
{
header: 'Halo 2',
flex: 1
}
]
});
rowNode.grid = sessionInstructionGrid;
sessionInstructionGrid.getEl().swallowEvent(['mouseover', 'mousedown', 'click', 'dblclick', 'onRowFocus']);
sessionInstructionGrid.fireEvent("bind", sessionInstructionGrid, {
ClientSessionId: record.get('ClientSessionId')
});
}
},
celldblclick: function(gr, td, cellIndex, record) {
//alert("###");
}
}
},
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name',
editor: {
allowBlank: false
}
},
{
text: 'Email',
dataIndex: 'email',
flex: 1
},
{
text: 'Phone',
dataIndex: 'phone'
}
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
Ext.create('Ext.button.Button', {
text: 'Hello',
handler: function() {
}
})
});
I would give the ComponentRowExpander plugin a try. It's intended to insert any component in a rowexpander - so it should work with a grid, too.

Extjs TreeStore data being ignored

I think I have everything correct here :
A simple model :
Ext.define('js.model.MyModel', {
extend: 'Ext.data.Model',
fields: [
{
name: "name",
type: "string"
},
{
name: "type",
type: "string"
}
]
});
A tree panel with tree store :
Ext.define('js.packageDialog.ReleaseTreeView.PackageTree', {
extend: 'Ext.tree.Panel',
rootVisible: true,
singleExpand: false,
initComponent: function () {
//Ext.create('js.model.MyModel');
Ext.apply(this, {
store: new Ext.data.TreeStore({
model: 'js.model.MyModel',
"root": {
"expanded": true,
"name": "",
"type": ""
},
proxy: {
type: 'memory'
//data: data
}
}),
columns: [
{
xtype: 'treecolumn',
text: 'Name',
dataIndex: 'name'
},
{
text: 'Parents',
dataIndex: 'parents'
}
]
});
this.callParent();
},
loadData : function() {
this.store.setRootNode(data);
}
});
Some data :
var data = Ext.JSON.encode({
"children": [{
"type": "folder",
"name": "Photos",
"children": [{
"type": "JPEG",
"name": "wedding picture"
}, {
"type": "JPEG",
"name": "holiday picture"
}
]
}]
});
I put all this together. See the fiddle :
http://jsfiddle.net/x527x57t/
And nothing is shown in the tree panel. The columns are correct, however my loadData() method does not work.
I have got it to work like so:
var data = {
children: [{
text: "Photos",
leaf:false,
children: [{
"type": "JPEG",
text: "wedding picture",
leaf:true
}, {
text: "holiday picture",
leaf:true
}]
}]
};
Ext.define('js.model.MyModel', {
extend: 'Ext.data.Model',
fields: [
{
name: "text",
type: "string"
},
{
name: "type",
type: "string"
},
{
name:"leaf"
}
]
});
Ext.define('js.packageDialog.ReleaseTreeView.PackageTree', {
extend: 'Ext.tree.Panel',
rootVisible: true,
singleExpand: false,
initComponent: function () {
Ext.apply(this, {
store: new Ext.data.TreeStore({
model: 'js.model.MyModel',
root: {
expanded: true
//type: ""
},
proxy: {
type: 'memory'
//data: data
}
})
});
this.callParent();
},
loadData : function() {
this.store.setRootNode(data);
}
});
So specifying which are leaf nodes in the data, also properties like the root of your TreeStore was wrapped in quotes, so I just amended. The data is now displaying. This may not be the 'correct' answer but one I can offer so far for you. Hope it helps.

ExtJS grouping grid cannot load JSON data

I am not able to load data in ExtJS grouping grid.
I have following code for ExtJS grouping.js.
Ext.onReady(function() {
Ext.QuickTips.init();
var xg = Ext.grid;
var documentType = "";
var fileName = "";
var size = "";
var fileGPath = "";
// shared reader
var reader = new Ext.data.ArrayReader({}, [{
name: 'filename'
}, {
name: 'size'
}, {
name: 'author'
}, {
name: 'date',
type: 'date',
dateFormat: 'Y-m-d H:i:s'
}, {
name: 'action'
}, {
name: 'document'
}
]);
var store = new Ext.data.GroupingStore({
reader: reader,
url: 'DocumentListService.jsp',
root: 'Documents',
sortInfo: {
field: 'filename',
direction: "ASC"
},
fields: [{
name: 'filename',
mapping: 'FileName'
}, {
name: 'size',
mapping: 'Size'
}, {
name: 'author',
mapping: 'Author'
}, {
name: 'date',
mapping: 'Date'
}, {
name: 'action',
mapping: ''
}, {
name: 'document',
mapping: 'Document'
}],
groupField: 'document'
});
var grid = new xg.GridPanel({
id: 'myGridId',
store: store,
columns: [{
id: 'filename',
header: "File Name",
width: 60,
sortable: true,
dataIndex: 'filename'
}, {
header: "Size",
width: 20,
sortable: true,
dataIndex: 'size'
}, {
header: "Author",
width: 20,
sortable: true,
dataIndex: 'author'
}, {
header: "Date",
width: 20,
sortable: true,
dataIndex: 'date'
}, {
header: "Action",
width: 20,
sortable: true,
dataIndex: 'action'
}, {
header: "Document",
width: 20,
sortable: true,
dataIndex: 'document',
hidden: 'true'
}],
view: new Ext.grid.GroupingView({
forceFit: true,
groupTextTpl: '{text} ({[values.rs[0].get("filename")=="" ? "0" : values.rs.length]} {[values.rs.length > 1 ? "Documents" : "Document"]}) <img src="images/image_add.png" alt="Upload Document" style="border:none;margin-left:390px;"/>'
}),
frame: true,
width: 700,
height: 450,
collapsible: true,
animCollapse: false,
title: 'Document Library',
iconCls: 'icon-grid',
renderTo: 'docUpload'
});
var fp = new Ext.FormPanel({
renderTo: 'fi-form',
fileUpload: true,
width: 500,
frame: true,
title: 'File Upload Form',
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{
xtype: 'fileuploadfield',
id: 'form-file',
emptyText: 'Select a File to import',
fieldLabel: 'File',
name: 'file',
buttonCfg: {
text: '',
iconCls: 'upload-icon'
},
listeners: {
'fileselected': function(v) {
if (fp.getForm().isValid()) {
fp.getForm().submit({
url: 'FileUpload.jsp',
waitMsg: 'Uploading your file...',
success: function(fp, jsonObj) {
fileName = jsonObj.result.fileName;
size = jsonObj.result.size;
fileGPath = jsonObj.result.fileGPath;
documentType = (document.getElementById("hdnId").value).replace("Document: ", "");
addDataToGrid(fileName, fileGPath, size, documentType);
Ext.getCmp('myGridId').getStore().loadData(xg.dummyData);
msg('Success', 'Successfully uploded on the server');
},
failure: function(fp, o) {
msg('Failure', 'Failed to upload');
}
});
}
}
}
}]
});
});
And I have following as json string in DocumentListService.jsp:
{
"DocumentList": [{
"DocumentGroup": "Invoice",
"isDocumentBundle": true,
"isWritable": true,
"Documents": [{
"FileName": "ABC.doc",
"Size": "123",
"Author": "xyz",
"Date": "\\/Date(1238025600000)\\/",
"FileGPath": "xyz doc",
"Document": "Invoice"
}, {
"FileName": "ABC.doc",
"Size": "123",
"Author": "xyz",
"Date": "\\/Date(1238025600000)\\/",
"FileGPath": "abc doc",
"Document": "Invoice"
}]
}, {
"DocumentGroup": "SOP",
"isDocumentBundle": true,
"isWritable": true,
"Documents": [{
"FileName": "ABC.doc",
"Size": "123",
"Author": "xyz",
"Date": "\\/Date(1238025600000)\\/",
"FileGPath": "xyz doc",
"Document": "SOP"
}]
}]
}
Still I am not able to load data.
Well your problem is the store reader, which has set as root "Documents" but the Json received has the root DocumentList. So the problem is mapping the json data to your store.
EDIT
The problem is that you are using incorectly the grouping store. The data does not need to be grouped when you are getting it from the backend.
Here is my suggestion
Json sent from back-end just a list of documents in which you have the type:
{
"Documents": [{
"Type": "invoice",
"FileName": "ABC.doc",
"Size": "123",
"Author": "xyz",
"Date": "\/Date(1238025600000)\/",
"FileGPath": "xyz doc",
"Document": "Invoice"
}, {
"Type": "invoice",
"FileName": "ABC.doc",
"Size": "123",
"Author": "xyz",
"Date": "\/Date(1238025600000)\/",
"FileGPath": "abc doc",
"Document": "Invoice"
}, {
"Type": "SOP",
"FileName": "ABC.doc",
"Size": "123",
"Author": "xyz",
"Date": "\/Date(1238025600000)\/",
"FileGPath": "xyz doc",
"Document": "SOP"
}]
}
And for the grouping store just use groupField: "Type" , And the reader should have the root Documents. This will simplify your load but it means you have to duplicate the extra data you need for each group and attach it to each document.
Is just a suggestion.

Resources