ExtJs grid paging not working - extjs

I can´t get my grid to work with paging. Here is my code (this code is executed inside the controller.js after the user types some information in a textField control):
var store = Ext.create('App.store.vo.Posts', {
autoLoad: {
params: {
query: textTyped,
start: 0,
limit: 10
},
callback: function (regs) {
me.getGrid().reconfigure(store);
me.getGrid().down('pagingtoolbar').bindStore(store);
}
}
});
and this is my store code:
Ext.define('App.store.vo.Posts', {
extend: 'Ext.data.Store',
model: 'App.model.vo.Post',
autoLoad: true,
autoSync: false
});
The grid populates with data correctly, but the paging is disabled.
UPDATE:
and the Post model:
Ext.define('App.model.vo.Post', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'auto'},
{name: 'text', type: 'auto'}
],
idProperty: 'id',
proxy: {
type: 'rest',
url : '/posts',
format: 'json',
reader: {
root: 'data',
successProperty: 'success',
totalProperty: 'total'
},
writer: {
// wrap post params for Rails
getRecordData: function(record) {
return { post: record.data };
}
}
}
});

I get this to work this way:
//set the 'query' param before load
var store = Ext.create('App.store.vo.Posts', {
listeners: {
beforeload: function(s,op, ot) {
op.params = {
query: filtro
}
}
}
});
store.load({
callback: function (regs) {
if (store.data.length > 0) {
me.getGrid().getView().focus(true, 200);
me.getGrid().getView().select(0);
}
},
params: {
query: filtro,
field: campo,
start: 0
}
});
me.getGrid().reconfigure(store);
me.getGrid().down('pagingtoolbar').bindStore(store);

You should try this (see Ext.data.Operation) :
autoLoad: {
start: 0,
limit: 10,
params: { ... },
callback: function () { ... }
}
Update
I'm wondering if pageSize is required to make pagination work. Default value is set to 25, maybe you should set this property according to your desired page size :
var store = Ext.create('App.store.vo.Posts', {
pageSize: 10

Related

ExtJs-> Ext.Store.proxy.writer error: No type specified for writer.create

So I have upgraded from extjs4 to extjs6 and this store always have this error:
No type specified for writer.create
This code has two uses:
For getting the data for the initial page
For getting the data for whenever a button is clicked.
Whenever I comment out the proxy.writer code portion, it will produce the data for the initial page.
But whenever I won't comment it out, it will not get the data for the initial page.
And it will also return this error whenever I clicked a button:
Uncaught TypeError: items.slice is not a function
So my question is, is the writer portion have wrong syntax or something since it is updated to extjs6?
P.S. I tried to change the
this.callOverridden to this.callParent since it states that the this.callOverridden is already deprecated, still has the same error.
Ext.define('Stm.store.stmpdate', {
extend: 'Extends.data.Store',
requires: [
'Cstm.Setting',
'Stm.model.stmpdate'
],
model: 'Stm.model.stmpdate',
pageSize: Stm.Const.controller.dataCountLimit,
remoteSort: true,
proxy: {
type: 'ajax',
url: Cstm.Setting.getEntryUrl() + '/stm/stm-update/stm-update',
reader: {
type: 'json',
rootProperty: 'data'
},
writer: Ext.data.writer.Json.override({
getRecordData: function() {
var data = this.callOverridden(arguments);
var record = arguments[0];
if ( record.associations.length > 0 ) {
Ext.Array.each(record.associations.keys, function(key) {
data[key] = [];
var assocStore = record[key]();
Ext.Array.each(assocStore.data.items, function(assocItem) {
data[key].push(assocItem.data);
});
});
}
return data;
}
}),
api: {
create: Cstm.Setting.getEntryUrl() + '/stm/stm-update/application',
update: Cstm.Setting.getEntryUrl() + '/stm/stm-update/approval'
},
actionMethods: {
create: 'POST',
read: 'POST',
update: 'POST',
destroy: 'POST'
}
},
sorters: [
{property: 'aplDatetime', direction: 'DESC'},
{property: 'siteDomain', direction: 'ASC'},
{property: 'pageName', direction: 'ASC'}
]
});
Model:
Ext.define('Stm.model.stmpdate', {
extend: 'Ext.data.Model',
fields: [
{name: 'siteId', type: 'integer'},
{name: 'siteName', type: 'string'},
{name: 'siteUrl', type: 'string'},
{name: 'tmpId', type: 'integer', defaultValue: 1},
{name: 'updType', type: 'string'}
],
hasMany: [{
model: 'Stm.model.ServerInfo',
name: 'servers',
associationKey: 'servers',
reference: 'tmpId'
}]
});
Yes, you are using override in a way that may have worked in ExtJS 4 but is AFAIK unsupported across all versions of ExtJS.
What you want to do is define your custom writer as a new class:
Ext.define('MyApp.app.data.MyCustomJsonWriter', {
extend: 'Ext.data.writer.Json',
alias: 'writer.mycustomjson',
getRecordData: function() {
var data = this.callParent(arguments);
var record = arguments[0];
if ( record.associations.length > 0 ) {
Ext.Array.each(record.associations.keys, function(key) {
data[key] = [];
var assocStore = record[key]();
Ext.Array.each(assocStore.data.items, function(assocItem) {
data[key].push(assocItem.data);
});
});
}
return data;
}
});
require that class from your store:
requires: [
'MyApp.app.data.MyCustomJsonWriter'
]
and then instantiate it by alias:
writer: {
type: 'mycustomjson'
}

ExtJS — How to load store data manually after ajax call?

I rewrite my working Fiddle from ajax proxy type to memory. I'm trying to load memory store data manually:
// app/model/Employees.js file
Ext.define('Fiddle.model.Employees', {
extend: 'Ext.data.Model',
entityName: 'Employees',
fields: [
{
name: 'profile_pic'
},
{
type: 'int',
name: 'age'
},
{
type: 'string',
name: 'last',
mapping: 'name.last'
},
{
type: 'string',
name: 'first',
mapping: 'name.first'
},
{
type: 'string',
name: 'email'
}
],
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty: 'items',
totalProperty: 'total',
successProperty: ''
}
}
});
// app/store/Employees.js file
Ext.define('Fiddle.store.Employees', {
extend: 'Ext.data.Store',
pageSize: 30, // items per page
alias: 'store.employees',
model: 'Fiddle.model.Employees',
});
//app.js fule - launch() function
var store = Ext.create('Fiddle.store.Employees');
console.log(store);
Ext.Ajax.request({
url: 'mates.json',
success: function(resp) {
var result = resp.responseText;
console.log(result);
// store.loadRawData(result);
store.loadData(result);
console.log(store);
console.log(store.getAt(0));
},
});
As result I have 3386 records in store, every symbol in my json file. And what I see in console as first record:
What I'm doing wrong?
And where I need to put proxy lines - in model or in store?
responseText is a string, which contains the serialized JSON data. You have to deserialize it into an object before you can use loadRawData to load the object through the model converters into the store:
var result = Ext.decode(resp.responseText);
store.loadRawData(result);
loadData and loadRawData differ in that loadData does not call the converters on the model. loadRawData is equivalent to what the ajax proxy does, loadData is not.
Did it in this way:
//in Grid panel js file
listeners: {
afterrender: function(grid, evt) {
var myStore = grid.getStore();
Ext.Ajax.request({
url: 'mates.json',
success: function(resp) {
var result = Ext.decode(resp.responseText);
myStore.getProxy().data = result;
myStore.load();
},
});
}
}
In store autoLoad: true must be disabled. This way of loading instead of store.loadRawData(result); shows the correct number of records in the pagingtoolbar.

ExtJS TreeStore is empty if I load store by manually

Model
Ext.define('MyDesktop.model.mail.MailFoldersModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.String'
],
fields: [
{
type: 'string',
name: 'id'
},
{
type: 'string',
name: 'idParent'
},
{
type: 'string',
name: 'text'
}
]
});
My TreeStore
Ext.define('MyDesktop.store.mail.MailFoldersStore', {
extend: 'Ext.data.TreeStore',
requires: [
'MyDesktop.model.mail.MailFoldersModel'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'MailFoldersStore',
model: 'MyDesktop.model.mail.MailFoldersModel',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'http://url/mail/folders',
reader: {
type: 'json',
rootProperty: 'items',
successProperty: 'success'
}
},
root: {
text: 'root',
iconCls: 'mail-folders-owner'
}
}, cfg)]);
}
});
Store is autoloaded, all works correctly, store contains 11 records.
var MailFoldersStore = Ext.create('MyDesktop.store.mail.MailFoldersStore', {
storeId: 'MailFoldersStore'
});
If I set autoLoad to false and trying to load by manually - store is empty, 0 records.
var MailFoldersStore = Ext.create('MyDesktop.store.mail.MailFoldersStore', {
storeId: 'MailFoldersStore'
});
MailFoldersStore.load({
callback : function(records, operation, success) {
console.log(records);
}
});
What can be a reason for this behaviour?
I also has same problem. I am using Extjs 5.1. After googling I found one complex solution which needs us to modify the framework.
See the below link if it can help you.
http://www.sencha.com/forum/showthread.php?154823-listeners-quot-exception-quot-in-proxy.ajax-on-TreeStore-do-not-work

store.sync after pressed OK button only reload the store

Ext.define('RouteSeqModel', {
extend: 'Ext.data.Model',
fields: [{name: '_id', type: 'number'}, {name: 'Route_Seq' , type: 'int'},'Location_Name','Route_LocationID','Route_ID']
});
var RouteSeqStore = Ext.create('Ext.data.JsonStore', {
model: 'RouteSeqModel',
storeId: 'RouteSeqStore',
autoLoad: false,
sorters: [{
property: 'Route_Seq',
direction: 'ASC'
}],
proxy: {
type: 'ajax',
url: 'get-routeseq.php',
api: {
create: 'insert-routeseq.php',
//read: 'http://visual04/ModuleGestion/php/Pays.php?action=read',
update: 'update-routeseq.php',
//destroy: 'http://visual04/ModuleGestion/php/Pays.php?action=destroy'
},
actionMethods: 'POST',
baseParams: {
_id : 0,
},
reader: {
type: 'json',
idProperty: '_id'
},
writer: {
type: 'json',
id: '_id'
}
}
});
RouteSeqStore.sync({
success: function(batch) {
//var button = Ext.getCmp('BtnRouteSeqRefresh');
//button.fireEvent('click', button); //need at here , if not too fast refresh will get the old data
grid.setLoading(false);
Ext.MessageBox.show({
title: "Information",
msg: batch.operations[0].request.scope.reader.jsonData["message"],
icon: Ext.MessageBox.INFO,
buttons: Ext.MessageBox.OK,
fn: function(buttonId) {
if (buttonId === "ok") {
//load store at here
}
}
});
},
failure: function(batch){
//var button = Ext.getCmp('BtnRouteSeqRefresh');
//button.fireEvent('click', button); //need at here , if not too fast refresh will get the old data
grid.setLoading(false);
RouteSeqStore.rejectChanges();
Ext.MessageBox.show({
title: "Error",
msg: batch.operations[0].request.scope.reader.jsonData["message"],
icon: Ext.MessageBox.ERROR,
buttons: Ext.MessageBox.OK,
fn: function(buttonId) {
if (buttonId === "ok") {
//load store at here
}
}
});
}
});
whenever called .sync function will automatically load the datastore with get-routeseq.php ,
is that have any way after pressing OK button only load the datastore(after pressed OK only call the get-routeseq.php)?
my autoLoad is false, but still automatically load the datastore.
I think you should use type: 'rest' and avoid url config in proxy.
Something like this:
var RouteSeqStore = Ext.create('Ext.data.JsonStore', {
model: 'RouteSeqModel',
storeId: 'RouteSeqStore',
autoLoad: false,
sorters: [{
property: 'Route_Seq',
direction: 'ASC'
}],
proxy: {
type: 'rest',
api: {
create: 'insert-routeseq.php',
read: 'get-routeseq.php',
update: 'update-routeseq.php',
//destroy: 'http://visual04/ModuleGestion/php/Pays.php?action=destroy'
},
actionMethods: 'POST',
baseParams: {
_id : 0,
},
reader: {
type: 'json',
idProperty: '_id'
},
writer: {
type: 'json',
id: '_id'
}
}
});
And if you want to just load store, use RouteSeqStore.load(). After you have made changes in store, use RouteSeqStore.sync().

Sencha Touch Sync Stores

I have two stores: localstorage and a json on the server, I'm trying to download data from json to the local. Please see what's wrong:
/store/Notes.js
Ext.define("NotesApp.store.Notes", {
extend: "Ext.data.Store",
requires: "Ext.data.proxy.LocalStorage",
config: {
storeId: 'Notes',
model: "NotesApp.model.Note",
proxy: {
type: 'localstorage',
id: 'notes-app-store'
},
sorters: [{
property: 'dateCreated',
direction: 'DESC'
}],
grouper: {
sortProperty: "dateCreated",
direction: "DESC",
groupFn: function (record) {
if (record && record.data.dateCreated) {
return record.data.dateCreated.toDateString();
} else {
return '';
}
}
}
}
});
/store/Online.js
Ext.define("NotesApp.store.Online", {
extend: "Ext.data.Store",
config: {
storeId: 'Online',
proxy: {
type: 'jsonp',
url: 'http://server.com/made/qa.php',
reader: {
type: 'json'
//rootProperty: 'results'
}
},
autoLoad: false,
listeners: {
load: function() {
console.log("updating");
// Clear proxy from offline store
Ext.getStore('Notes').proxy.clear();
console.log("updating1");
// Loop through records and fill the offline store
this.each(function(record) {
console.log("updating2");
Ext.getStore('Notes').add(record.data);
});
// Sync the offline store
Ext.getStore('Notes').sync();
console.log("updating3");
// Remove data from online store
this.removeAll();
console.log("updated");
}
},
fields: [
{
name: 'id'
},
{
name: 'date_created'
},
{
name: 'question'
},
{
name: 'answer'
},
{
name: 'type'
},
{
name: 'author'
}
]
} });
When I need to update I called Ext.getStore('Online').load();
But the console is not showing anything else after 'updating'.
I wonder what went wrong?
Use Ext.getStore('Notes').getProxy().clear() instead works

Resources