Sencha Ext JS data not showing in grid - extjs

Hi im new to Sencha Extjs im trying to pull the data from the API that i created in asp.net.
in the developer tools i can get the data but it is not showing in the grid. Can anyone help?
here is the code that i did.
This is the Model
Ext.define('VidlyViews.model.Customers', {
extend: 'VidlyViews.model.Base',
fields: [
'name', 'membershipType', 'isSubscribeToNewsLetter', 'birthDate'
]
});
This is the Store.
Ext.define('VidlyViews.store.Customers', {
extend: 'Ext.data.Store',
alias: 'store.customers',
model: 'VidlyViews.model.Customers',
autoLoad: true,
proxy: {
type: 'jsonp',
url: 'https://localhost:44300/api/customers',
reader: {
type: 'json',
rootProperty: 'feed.entry'
}
}
});
This is in the classic/src/view/main folder
Ext.define('VidlyViews.view.main.Customers', {
extend: 'Ext.grid.Panel',
xtype: 'customerlist',
requires: [
'VidlyViews.store.Customers'
],
title: 'Customers',
store: {
type: 'customers'
},
columns: [
{ text: 'Customer Name', dataIndex: 'name', flex: 1 },
{ text: 'Membership Type', dataIndex: 'membershipType', flex: 1 },
{ text: 'Newsletter', dataIndex: 'isSubscribeToNewsLetter', flex: 1 },
{ text: 'Birthdate', dataIndex: 'birthDate', flex: 1 }
],
listeners: {
select: 'onItemSelected'
}
});
Thank you in advance

i fixed my problem and i hope it can help others in the future.
i changed my proxy to this:
proxy : {
type : 'rest',
actionMethods : {
read : 'GET'
},
url : 'https://localhost:44300/api/customers',
useDefaultXhrHeader: false,
reader: {
type : 'json',
headers: { 'Accept': 'application/json' },
allDataOptions: {
associated: true,
persist: true
},
rootProperty : 'data'
},
}
I used restto pull the data. and the rootPropery is the data.
In the API (ASP.NET) i modified the IhhtpActionResult to this
public IHttpActionResult GetCustomers(int start, int limit)
because in sencha you can get the start and limit of the pagination and use .Skip() and .Take() on the backend.
it looks like this:
var customerDtos = customersQuery
.OrderBy(c => c.CustomerId)
.Skip(start)
.Take(limit)
.ToList();
and the last step that i did is to return the data like this:
return Ok(new { total = customerDtos.Count(), data = customerDtos });
the data is recognized in the rootProperty as the collection of data and the total is the total count of the data that can be recognized in the API call.
I hope it helps. It took me a whole day to figure it out hahaha

Related

Local gridfilters

in ExtJS 4 i could create a filter to filter my grid.
When is set local to false, i could filter my store.
var filtersCfg = {
ftype: 'filters',
autoReload: false, //don't reload automatically
local: false, //remote filter
// filters may be configured through the plugin,
// or in the column definition within the headers configuration
filters: [{
type: 'numeric',
dataIndex: 'id'
}, {
type: 'string',
dataIndex: 'name'
}, {
type: 'numeric',
dataIndex: 'price'
}, {
type: 'date',
dataIndex: 'dateAdded'
}, {
type: 'list',
dataIndex: 'size',
options: ['extra small', 'small', 'medium', 'large', 'extra large'],
phpMode: true
}, {
type: 'boolean',
dataIndex: 'visible'
}]
};
In EXTJS 7 i can only add a plugin:
plugins: {
gridfilters: true
},
How can i add a remote filter in EXTJS 7. Is this still possible? I can't find anything in the documentation.
Best regards
Edit:
I'm using a data.Store to get a json from my php/database. Sorting over the grid is not a problem. But how can i use a filter to send the parameters to my php?
var Store = new Ext.data.Store({
extend: 'Ext.data.Store',
autoLoad: true,
remoteSort: true,
fields: [
'columnA','columnB'
],
pageSize : 50,
proxy: {
type: 'ajax',
actionMethods: {
create : 'POST',
read : 'POST',
update : 'POST',
destroy: 'POST'
},
url: 'data/URL.php',
reader: {
rootProperty: 'columns',
totalProperty: 'totalCount'
},
simpleSortMode: true,
extraParams: {
task: 'doFiltering'
}
},
sorters: [{
property: 'columnA',
direction: 'DESC'
}]
});
I found the solution.
I need to add remoteFilter: true to my store.
The whole time i was searching on the wrong place.
This was the solution: How to apply filter function to paging grid with local(memory) store in ExtJS6?
Thank you for your help.
In ExtJS 7 you must put filter config in column.
...
{
text: 'Email',
dataIndex: 'email',
flex: 1,
filter: {
type: 'string',
value: 'lisa'
}
},
...
Fiddle

extjs how to pass parameters to a web rest api request

I'm now trying to connect Extjs with a web rest api apart from my project. This is my view:
Ext.define('mycomponents.view.comboselview', {
extend: 'Ext.container.Container',
id: 'comboview',
alias: 'widget.comboview',
xtype: 'comboview',
requires: [
'mycomponents.model.comboselmodel'
],
items: [
{
xtype: 'combobox',
reference: 'levels',
publishes: 'value',
fieldLabel: 'Choices',
displayField: 'description',
anchor: '-15',
store: {
type: 'levels'
},
minChars: 0,
queryMode: 'local',
typeAhead: true,
labelWidth: 100,
labelAlign : 'right',
width: 265,
allowBlank: false
}
],
initComponent: function () {
this.callParent(arguments);
var that = this;
console.log('!!!!!!!!!!!!!!!!!!!!!!>>>', that.up());
}
});
Here is my model:
Ext.define('mycomponents.model.comboselmodel', {
extend: 'Ext.data.Model',
fields: [
{
name: 'id',
mapping: 'pk'
},
{
name: 'description',
type: 'string',
mapping: 'description'
},
{
name: 'levelid',
type: 'integer',
mapping: 'levelid'
},
...
]
});
and my store:
Ext.define('mycomponents.store.comboselstore', {
extend: 'Ext.data.Store',
alias: 'store.levels',
model: 'mycomponents.model.comboselmodel',
storeId: 'levels',
restful: true,
autoLoad: true,
proxy: {
type: 'ajax',
headers: {
'Accept': '*/*',
'Cache-Control': 'no-cache',
'Content-Type': 'application/json',
'Authorization': localStorage.token
},
extraParamas: {
sort: 'description',
filter: {
idlevel: {
'null': -1
}
}
},
reader: new Ext.data.JsonReader({
}),
writer: new Ext.data.JsonWriter({
}),
actionMethods: {
read: 'GET'
},
api: {
read: 'apiurl',
create: 'apiurl',
update: 'apiurl',
destroy: 'apiurl'
},
autoSave: true
},
constructor: function (config) {
this.callParent([config]);
console.log('I am entering here!!!')
}
});
I'm trying to fetch resources from my apiurl which is a web rest api. I need to send some parameters, this code returns me the desired data, but this approach ignores the extraParamas at all. I can't tell that I went into the documentation and found how to use Extjs with a rest api becasue I was unable to find how to do that in the official documentation, so, I've been googleing for a solution and what I've made so far is getting code snippets from here and there. My question: how to send paramenters to a rest api? what am I doing wrong?
There's a typo in your code, extraParamas, when it should be extraParams

ExtJS Loading Link List Tree Using Ajax

I have the below code that I am trying to get the list of dates using Ajax and display those on the page as links to elsewhere. So each entry would be a link that when you click would take you elsewhere. Though the treelist is not loading any items...
Data
{
"success": true,
"data": [
"2018-10-08T00:00:00",
"2018-10-05T00:00:00",
"2018-10-04T00:00:00",
"2018-10-03T00:00:00",
]
}
Code
Ext.define('...', {
extend: 'Ext.form.Panel',
xtype: '...',
requires: [
'...'
],
layout: 'border',
items: [{
xtype: 'container',
store: {
proxy: {
type: 'ajax',
url: '...',
useDefaultXhrHeader: true,
withCredentials: true,
reader: {
type: 'json',
rootProperty: 'data'
},
}
}
}]
});
You can display a grid with your data. It can show clickable links.
To do this you need to make a grid with your ajax store and a grid renderer like this:
// Ajax store
Ext.create('Ext.data.Store', {
storeId: 'mystore',
autoLoad: true,
proxy: {
type : 'ajax',
url : '/file.php',
actionMethods: {
read: 'POST'
},
reader : {
type: 'json'
},
extraParams : {
key : 'val'
},
fields : [
{name: 'date', type: 'string'}
]
}
})
// Grid
Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
scrollable: true,
store: {
type: 'mystore'
},
columns: [
{
text: 'link column',
dataIndex:'link',
renderer: function(value) {
if(value) {
// here you can format your output
return ''+value+'';
}
}
}
]
})
Please look whole example in a Fiddle

Issue with Row Editing Plugin in Extjs

I have a fully working liveSearchGridPanel in ExtJs. Error occurs when I edit any row. What Happens is that if the the updated row has to be resorted like in my case when I change the age of user (I am sorting on basis of age) row goes up or down in the grid, but the previous record remain there as well until I refresh the entire webpage manually. Screenshot is below
My proxy model is:
Ext.define('proxymodel', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'int',
persist: false
}, {
name: 'gender',
type: 'auto'
}, {
name: 'name',
type: 'auto'
}, {
name: 'age',
type: 'int'
}],
identifier: 'sequential', // to generate -1, -2 etc on the client
proxy: {
type: 'rest',
//format: 'json',
//appendId: false,
idParam: "id",
//limitParam:"",
//filterParam: "",
//startParam:'',
//pageParam:'',
url: 'http://localhost:3000/posts',
api: {
read: 'http://localhost:3000/db',
create: 'http://localhost:3000/posts',
update: 'http://localhost:3000/posts',
destroy: 'http://localhost:3000/posts'
},
headers: {
'Content-Type': "application/json"
},
reader: {
type: 'json',
rootProperty: 'posts',
totalProperty: 'total'
},
writer: {
type: 'json'
}
}
});
In Application.js, I have defined row editing plugin as:
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
listeners: {
cancelEdit: function(rowEditing, context) {
// Canceling editing of a locally added, unsaved record: remove it
if (context.record.phantom) {
store.remove(context.record);
}
},
edit: function(editor, e) {
// commit the changes right after editing finished
e.record.commit();
}
}
});
And my store looks like:
Ext.define('Store', {
extend: 'Ext.data.Store',
storeId: 'peopleStore',
pageSize: 500,
//buffered: true,
//leadingBufferZone: 300,
pageSize: 5,
autoLoad: {
start: 0,
limit: 5
},
autoSync: true,
sorters: [{
property: 'age',
direction: 'ASC'
}],
groupField: 'gender'
});
Can anyone point out my mistake?
I have tried to reload my store after editing in 'edit' function of rowEditing but it didn't work.
Thanks for your time.
As full answer by request:
Have you tried Ext.data.StoreManager.lookup('peopleStore').reload() ?

Grid Sencha Ext doesn't load data although the store have

I'm new in Sencha and in my project, there have a button when you clicked in it will send the request to the server and show the value that returned back in Json form.
I've check and the store have value but I don't know why the grid panel is empty
here my function to send request and load the data into grid
loadVersion: function(i_chronicle_id){
Ext.getCmp('documentVersionsPanel').body.update('<i>Loading...<i>');
var documentVersionStore = new Ext.create('Ext.data.Store',{
storeId:'documentVersion',
fields:['documentID', 'documentVersion', 'documentStatus'],
proxy: {
type: 'ajax',
actionMethods: 'post',
url: 'ajaxAction?action=getDocumentVersion',
extraParams: {
format: 'json',
documentID: documentID,
},
reader: {
type: 'json',
root: 'jsonList'
}
}
});
Ext.getCmp('documentVersionsPanel').store = documentVersionStore;
Ext.getCmp('documentVersionsPanel').getStore().reload();
and the grid panel
{
xtype: 'gridpanel',
title: 'Versions',
id: 'documentVersionsPanel',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'documentVersion',
id: 'versionColumn',
text: 'Version'
},
{
xtype: 'gridcolumn',
dataIndex: 'documentStatus',
id: 'statusColumn',
text: 'Status'
}
]
},

Resources