Ext Js store parameters change when the grid page changes - javascript

I have a grid of which store is filtered in server side. This is the store:
var _store = Ext.create('Ext.data.Store', {
model: isemriModel,
storeId: 'storeFiltered' + _id,
pageSize: 5,
autoLoad: { filter: JSON.stringify(filterObject) },
proxy: {
type: 'ajax',
actionMethods: {
read: 'POST'
},
url: _url,
extraParams: {
kullaniciAdi: _userName,
sifre: _password,
filter: JSON.stringify(filterObject)
},
reader: {
rootProperty: 'isemirleri',
totalProperty: 'totalCount'
}
},
listeners: {
beforeload: function (store, operation, opts) {
},
load: function (store) {
}
}
});
Here is my problem: When I make a search for records which contains specific letters, names etc (for example names containing a). First page appears correct. But when I change the grid page from paging toolbar, filter parameter is cleared and non filtered records appears.
I also tried
store.load({ params: { filter: JSON.stringify(filterObject) } });
but it does not work. Can anybody help?
Attention: I make the filtering at server side, not at ext store. Is it possible to load store with dynamically changing parameters using a grid with paging toolbar.

on load function set again your filter to the current page.
Also if the store is the same, pages have differents filters. Infact probably if you try to return to the filtered page you'll se the filter isn't cleared.
simply every page can have a different filter.
remember to clear all page filters if you use the same filter in more than one page

You should use
remoteFilter: true
and the built-in filter functions for your store. Your proxy page _url will get the filter by an other way but your filter will be kept between different loads.

Related

Setting data into a Kendo DataSource Without Ajax

I have some client-side JSON and want to use to "quickly" experiment with various controls without writing all the REST API calls. All I want to do is point any given Kendo DataSource to the local array of data I already have instead of writing all the extra's...but nothing I do works.
I have tried various online examples...can someone direct me to something that actually works?
EXAMPLE:
This particular example is for their Donut Chart using Angular, but I cant use their data calls because of CORS & I am getting tired of writing a new set of REST calls every time I merely want to experiment with a particular control.
var data = [{ ... }, { ... }]
$scope.screenResolution = new kendo.data.DataSource({
// I dont want this at the moment
//transport: {
// read: {
// url: "http://demos.telerik.com/kendo-ui/content/dataviz/js/screen_resolution.json",
// dataType: "json"
// }
//},
sort: {
field: "order",
dir: "asc"
},
group: {
field: "year"
}
});
Datasource has a data property that you can set to a local array.
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-data

How can I show custom events on Kendo UI Scheduler?

I have a Kendo UI Scheduler with a timeline view in which as one of the resources, a list of Persons names are being dynamically populated in the Scheduler. To get that data, I created a remote webservice responsible to get a proper communication between the database and the front-end. When I created the web service, I also created a method called GetPersons in VB that retrieves me the data in JSON format for me to use.
resources: [{
field: "UserID",
name: "Persons",
dataTextField: "Name",
dataValueField: "Name",
dataSource: new kendo.data.DataSource({
transport: {
read: {
url: 'Service/JSON/GetPersons'
},
schema: {
type: "json",
data: "GetPersonsResult.RootResults"
}
}
),
multiple: true,
title: "name"
Now, to explain my issue:
I have a table on the database with the following fields: ID, PersonID, TypeOfEventID, startDate and endDate. In this table, I created three events just to try testing and to be related with the Persons.
I am trying to see in the Scheduler all those events I created but so far, nothing shows up. My logic was the same as with the GetPersons method. I created a new VB file called GetEvents to get me the events in the web service from the database to be retrieved and used in JSON format later. With this JSON data, I was planning to see the events I created. Just like it happend with the GetPersons method.
The view used it's a custom one based on the timelineMonth type. Every row has a different Person name and for each Person, specific events of different types might be seen.
Here's a fiddle with my script
So far, I can not see any events neither the Scheduler pop-window that shows up when I do double click inside the Scheduler.
Any tip of how to associate all these sort of things? I have no idea if I need to create another dataSource, neither I know what to put exactly on the resources and/or schema/model section.
One month after, nobody answered to my question and because of this I believe that I should post the solution:
The main thing that I had to do, was to create my second type of resources in a proper way. So, very simply... I did this:
{
field: "EventType",
dataValueField: "EventTypeID",
dataTextField: "descr",
dataColorField: "Color",
dataSource: new kendo.data.DataSource({
transport: {
read: {
url: './../Services/BlahBlahBlahDomainService.svc/JSON/GetEventType'
}
},
schema: {
type: "json",
data: "GetEventsTypeResult.RootResults",
total: "GetEventsTypeResult.TotalCount"
}
}
)
}
Besides that, I discovered some other little issues. For example:
the editable option was disabled;
both resources dataSource had no "schema.total" field defined and that options is needeed once the "schema.data" field is called;
a "dataTextField" property from one of the resources was missed;

how to make the URL tag of a store dynamic rather than giving it a constant string in sencha touch

I am stuck with this problem for a while and not able to find a solution anywhere
Ext.define('RmitPorject.store.Alerts', {
extend: 'Ext.data.Store',
/* gCameraID: function(){
var d = this.data,
id =d.CameraID
return id.join(" ");
},*/
config: {
model: 'RmitPorject.model.Alert',
//sorters: 'CameraID',
autoLoad: true,
proxy: {
type: 'ajax',
// url: 'txt.json',
url: 'Camera/'+'100001'+'.json',
/*here, we have to make a dynamic loading url
* for example, we need to make a function handler
* It will handle the particular cameraid to request different folder camerid (url)
* *
* */
//url:'http://52.64.86.42/RmitPorject/txt.json',
reader: {
type: 'json',
rootProperty: 'data'
}
}
}
});
this is a store file
what i want is when the user touches one of the item from the list it will use this store file to load that particular list item's JSON file.
but i don't know how to transfer that list item's value to this store file so that it knows what JSON file to use
In other words , I want to make this URL tag dynamic depending on the user's response it should load data from a different JSON files , but unfortunately i dont know how to make this store dynamic.
on user's response you can change store's url and then load store using below code
Ext.getStore('Alerts').getProxy().setUrl('Camera/'+'100001'+'.json');// create dynamic url string and pass it in setUrl method
Ext.getStore('Alerts').load();
remove "autoLoad:true" because it trys to load store instantly , might it will give you error.

Extjs 4, How to send multiple metaData for multiple dynamic grids, using a single Json file

I need to create 8-10 grids on a single panel, using accordion Layout. All grids would be created dynamically using the metaData object in JSON and metachange listener event on my store and reconfigure my grid accordingly (Pretty standard process) . But is there a way to use a single JSON file containing metaData and Data of more than one grid. So that I can use multiple stores to read a single JSON.
Something Like this would be good:
"grid1" :
{
"metaData" : {---"root":"data1"-----------}
},
"grid2" :
{
"metaData" : {----"root":"data2"----------}
},
"data1" : {------------------},
"data2" : {-----------------}
I already tried using metaProperty tag in my store, but that approach doesn't seem to work for me(ExtJs 4.1.3) .
Store Proxy:
proxy: {
type: 'ajax',
url: 'MultiData.json',
reader: {
type: 'json'
// metaProperty : 'grid1', //Doesn't work, hence commented
}
Store Listener:
'metachange' :function (store, meta) {
Grid.reconfigure(store, meta.columns);
}
NOTE: The above code works perfectly when I have only one metaData and data tag in JSON
How about this :
Get all the data you need using a single Ext.Ajax Call
Split the data into parts as you need.
use store.loadData() to load directly to store. This should also trigger the metachange listener and configure the grid accordingly. If it doesn't you can use the configure() property of the grid : grid.reconfigure(store,columns)
http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-loadData
http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.grid.Panel-method-reconfigure

In ExtJS does getForm().load() load combo field values?

I have a form with a combo box in it. The combo box loads it's data via a Json store and I use form.getForm().load( url: 'URL') to load the forms data also from a Json store.
When the data is loaded into the form I can see via Firebug that it receives the right value, the combo then displays the correct corresponding display value. When I look at the HTML in FireBug for the hiddenField it says the value="DISPLAYVALUE" not value="VALUE". When I then pick any value from the combo it changes to the correct value="VALUE".
Of course if the user never changes the combo the wrong value is submitted. Is this by design/limitation or am I missing something.
Do I really need to load and verify the data for each combo before I do the getForm().load()? wouldn't it make sense for load() to just load the complete data even if that means loading the data from a store?
I've included simplified sample code that has the issue.
Ext.onReady(function(){
var frmClientRecord = {
xtype: 'form',
items: [
{
fieldLabel: 'Advisor',
xtype: 'combo',
id: 'advisorName',
displayField: 'Advisor',
valueField: 'advisorId',
hiddenName: 'advisorsId',
mode: 'remote',
store: new Ext.data.Store({
autoLoad: true,
proxy: new Ext.data.HttpProxy({
url: '/referrals/index.php/advisors/read',
method: 'POST'
}),
reader: new Ext.data.JsonReader({
root: 'results',
fields: [
{name: 'advisorId'},
{name: 'Advisor'}
]
})
})
}
]
}
frmClientRecordCmp = new Ext.FormPanel(Ext.apply(frmClientRecord));
frmClientRecordCmp.getForm().load({
url: '/referrals/index.php/clients/getbyid/100',
})
frmClientRecordCmp.render(document.body);
});
JSON FOR THE COMBO
({"results":[{"Advisor":"Chris","advisorId":33},{"Advisor":"Fawzia","advisorId":2},{"Advisor":"Kent","advisorId":3},{"Advisor":"Rob","advisorId":4},{"Advisor":"Stephanie","advisorId":5}]})
JSON FOR THE FORM
{success: true, data: {"advisorsId":33}}
This could happen if your form is loading before the combo store loads. (Given that rest of your code looks Ok)
I suspect this will resolve if you render your form before loading it.
(move frmClientRecordCmp.render(document.body); one statement up in your sample code)
EDIT
Two points to consider-
Are you sure the combo store has finished loading before the form loads?
Looking at ComboBox's valueField documentation, it looks like a call to combo.setValue may be necessary after the form loads. Something along the lines of -
frmClientRecordCmp.getForm().load({
url: '/referrals/index.php/clients/getbyid/100',
success:function(form,action){
form.findField('advisorName').setValue(action.result.data.advisorId);
}
});
It was a problem I had caused by using the id: 'advisorName'. I was returning a field also named 'advisorName' so it was filling it even though I was specifying a hiddenName value. The moral is make sure your id is unique and not a field name.

Categories