I am trying to create two combo boxes, one enabling users to select a state and the other a local government area (LGA), and have it so the LGAs are filtered on the basis of the state selected. I'm using Ext 3.4 and populating data stores using an AJAX request. The filtering is being done with a REST query to Django.
I believe the issue I'm having is coming down to variable scope, as the first combo box works fine but once I select a state I get an error stating "Uncaught TypeError: Cannot call method 'request' of undefined" when I'm trying to load the URL for the LGA combo box's data store. I've indicated where this is happening with a comment in the code (see below). I'm struggling to understand how I need to rejig the code to make things work. I'm a bit of a newbie to programming so apologies if the solution is a simple one. My code is below.
Thanks in advance for any help.
Ext.onReady(function() {
var stateStore = new Ext.data.JsonStore({
autoDestroy: true,
url: 'states.json',
storeId: 'ste-store',
root: 'records',
id: 'ste-store',
fields: ['state']
});
var lgaStore = new Ext.data.JsonStore({
autoDestroy: true,
url: '',
storeId: 'lga-store',
root: 'records',
id: 'lga-store',
fields: ['lga']
});
var stateCombo = new Ext.form.ComboBox({
renderTo: document.body,
id: 'ste-cb',
typeAhead: true,
triggerAction: 'all',
lazyRender: true,
mode: 'local',
store: stateStore,
displayField: 'state',
valueField: 'state',
listeners: {
render: function(e) {this.getStore().load()},
select: function(combo, record, index) {
var selectedState = record.get('state');
var lgaUrl = 'lgas.json?state=' + selectedState;
lgaStore.url = lgaUrl; //Error is traced back to here
lgaCombo.getStore().load();
}
}
});
var lgaCombo = new Ext.form.ComboBox({
renderTo: document.body,
id: 'lga-cb',
typeAhead: true,
triggerAction: 'all',
lazyRender: true,
mode: 'local',
store: lgaStore,
displayField: 'lga',
valueField: 'lga',
});
});
first mistake of your code in mode. If you fetching data from back-end mode should be remote.
Another i advice your use select event of first combo box to get the data from server .
here is my two combo box which fetch the data remotely
new Ext.form.ComboBox({
id:"myB",
hiddenName:'myserId',
store: myStore(),
emptyText:'Select App ...',
fieldLabel:'Apps',
displayField: 'name',
valueField: 'id',
typeAhead: true,
forceSelection: true,
triggerAction: 'all',
mode:'remote',
maxLength: 50,
editable: false,
listWidth : 345,
anchor : '90%',
selectOnFocus:true,
listeners: {
// 'select' will be fired as soon as an item in the ComboBox is selected with mouse, keyboard.
select: function(combo, record, index){
var geoStorageCB = Ext.getCmp('geoCB');
geoStorageCB.getStore().proxy.setUrl('../test', true);
geoStorageCB.getStore().load({
params:{
id:combo.getValue()
}
});
}
}
}),new Ext.form.ComboBox({
id:"geoCB",
hiddenName:'geoId',
hidden : true,
store:myGeoStorage(),
emptyText:'Select GeoStorage ...',
displayField: 'storageName',
valueField: 'id',
typeAhead: true,
forceSelection: true,
triggerAction: 'all',
mode:'local',
listWidth : 345,
editable: false,
maxLength: 50,
anchor : '90%',
selectOnFocus:true
})
This Example from sencha forum can give you an idea how cascading combo works. I think the main problem of your code is your lgaStore loading method (inside stateCombo listener) doesn't use correct way to pass parameters to Django for the query. As naresh mentioned, you'd better use "lgaCombo.getStore().load({params:{...}});"
Related
I have a grid in ExtJs 4.2. I need to apply remote sorting, remort filtering and pagination. So my store look like this:
storeId: 'mainStore',
pageSize: 10,
autoLoad: {
start: 0,
limit: 10
},
autoSync: true,
remoteSort: 'true', //For Remote Sorting
sorters: [{
property: 'COM_KOP_Vertriebsprojektnummer'
direction: 'ASC'
}],
remoteFilter: true, //For Remote Filtering
proxy: {
type: 'rest',
filterParam: 'filter',
url: PfalzkomApp.Utilities.urlGetData(),
headers: {
'Content-Type': "application/xml"
},
reader: {
type: 'xml',
record: 'record',
rootProperty: 'xmlData'
}
}
I do not want to set buffered = true case that will load my pages in advance and I have 1000 pages and I don't want to do that.
Remote filtering, Pagination, sorting is working fine But when I try to filter some thing, a seprate request for sorting is going as well. How can I stop it?
two requests when I try to filter some thing:
http://127.0.0.1/projektierungen/?_dc=1437058620730&page=1&start=0&limit=10&sort=[{"property":"COM_KOP_Vertriebsprojektnummer","direction":"DESC"}]
http://127.0.0.1/projektierungen/?_dc=1437058620734&page=1&start=0&limit=10&sort=[{"property":"COM_KOP_Vertriebsprojektnummer","direction":"DESC"}]&filter=[{"property":"COM_KOP_Vertriebsprojektnummer","value":"2882"}]
How can I stop the first request?
My code for filtering column is this:
{
text: 'Vertriebsprojektnr',
dataIndex: 'COM_KOP_Vertriebsprojektnummer',
flex: 1,
items : {
xtype:'textfield',
flex : 1,
margin: 2,
enableKeyEvents: true,
listeners: {
keyup: function() {
var store = Ext.getStore('mainStore');
store.clearFilter();
if (this.value) {
//debugger;
//debugger;
store.filter({
property : 'COM_KOP_Vertriebsprojektnummer',
value : this.value,
anyMatch : true,
caseSensitive : false
});
}
},
buffer: 1000,
}
}
}
Due to this auto genrated request, my view is not working fine. As the result after filtering are replaced by this sorting request.
Kindly help.
The extra request is not there because of sorting but because of the call to store.clearFilter(). Try to call store.clearFilter(true) that suppresses the event what could prevent that extra request.
Why are you clearing you filters when the value is empty? Why not filter on an empty value? I almost got the same situation, but I think my solution works well without clearing anything. Besides that I don't want to know which store to filter or have the property name hardcoded. Here is my filterfield:
Ext.define('Fiddle.form.TextField', {
extend: 'Ext.form.field.Text',
alias: 'widget.filterfield',
emptyText: 'Filter',
width: '100%',
cls: 'filter',
enableKeyEvents: true,
listeners: {
keyup: {
fn: function(field, event, eOpts) {
this.up('grid').getStore().filter(new Ext.util.Filter({
anyMatch: true,
disableOnEmpty: true,
property: field.up('gridcolumn').dataIndex,
value : field.getValue()
}));
},
buffer: 250
}
}
});
And here is the view declaration:
dataIndex: 'company',
text: 'Company',
flex: 1,
items: [{
xtype: 'filterfield'
}]
How to add grid view in MVC-6?
I would like to use webgrid something for listing the details. Is it possible to use System.Web.Helpers as namespace. But I am not getting it supporting
This project could fit your requirements, a simple grid control for ASPNET MVC (using Razor): MVC6.Grid.Web
You can also try NetCoreControls.
Built specifically for .NET MVC Core.
The Grid Control is server side, uses AJAX, and supports, paging, filter and events.
Check the documentation and demo website.
You can use the Shield UI for ASP.NET Core NuGet package and integrate it with the free Shield UI Lite via Bower, or the commercial Shield UI suite.
Their Grid widget is awesome!
I would suggest to use the jqGrid(or may be some other java scripts grid). From the MVC controller return the ActionResult as JSON object
public ActionResult UserList()
{
object userListData = null;
try
{
List<UserListViewModel> users = 'your code to get the user list'
userListData = new
{
page = 1,
records = users.Count,
rows = users
};
}
JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = int.MaxValue;
return new ContentResult()
{
Content = serializer.Serialize(userListData),
ContentType = "application/json",
};
}
and call this on page load/jQuery document Ready some thing like this.
$("#userTable").jqGrid({
url: '../User/UserList,
mtype: 'GET',
datatype: "json",
autowidth: true,
colNames: ['Id', 'First Name', 'Last Name'],
colModel: [
{ name: 'Id', key: true, hidden: true, fixed: false, shrinkToFit: false, align: 'left' },
{ name: 'FirstName', fixed: false, shrinkToFit: false, align: 'left' },
{ name: 'LastName', fixed: false, shrinkToFit: false, align: 'left' }
],
for more information about jqGrid, please see demo at http://jqgrid.com/
I want to add a combobox in my app with a remote store. I have a store that call a php script that returns data in json format and I linked it with my combobox.
The store is autoLoaded but my combobox is still empty.
Here's my store
// Define autocomplete model
Ext.define('modelloAC', {
extend: 'Ext.data.Model',
fields: [
{ name: 'telaio' }
]
});
// store auto complete
var autoCompleteStore = Ext.create('Ext.data.Store', {
model: modelloAC,
autoLoad: true,
proxy: {
type: 'ajax',
url: 'script/request.php?operazione=gettelai',
reader: {
type: 'json',
root: 'telai',
totalProperty: 'results'
}
}
});
My PHP return a JSON array:
{"results":207,"telai":[{"telaio":"ZAR93200001271042"},{"telaio":"ZLA84000001738127"},{"telaio":"VF3WC9HXC33751301"},{"telaio":"W0L0AHL3555247737"}]}
My combobox:
xtype: 'combo',
name: 'telaio',
//hideTrigger: true,
store: autoCompleteStore,
typeAhead: true,
queryMode: 'remote',
fieldLabel: 'Telaio'
My store loads perfectly but my combobox is empty, where's the problem?
Need to add displayField and valueField in combo config:
...
displayField: 'telaio',
valueField: 'telaio',
...
Also model in your store is undefined now. Write it as a string:
...
model: 'modelloAC',
...
I have a grid which uses a remote store and remote pagination because I have too many records.The store for the main grid is:
Ext.define('ArD.store.RecordsListStore', {
extend: 'Ext.data.Store',
model: 'ArD.model.RecordsListModel',
autoLoad: true,
autoSync: true,
remoteSort: true,
remoteFilter: true,
pageSize: 15,
proxy: {
type: 'ajax',
actionMethods: 'POST',
api: {
read: g_settings.baseUrl + 'index.php/recordslist/getAll',
destroy: g_settings.baseUrl + 'index.php/recordslist/deleteRecord'
},
reader: {
type: 'json',
root: 'data',
totalProperty: 'totalCount',
successProperty: 'success'
},
writer: {
root: 'data',
writeAllFields: true,
encode: true
}
}
});
then I populate my grid and and it's all fine. But the problem is that I have a combobox which looks like this:
{
xtype: 'combo',
id: 'records_list_form_id',
emptyText: 'Choose Form',
editable: false,
store: 'FilterRecordsByForm',
displayField: 'title',
valueField: 'id',
lastQuery: '',
triggerAction: 'all',
queryMode: 'remote',
typeAhead: false,
width: 200,
listeners: {
select: this._filterRecords
}
}
And when I select something from the combobox there's the function :
_filterRecords: function()
{
var recStore = Ext.getStore('RecordsListStore');
var a = Ext.getCmp('records_list_form_id').getValue( );
var rec = Ext.getStore('FilterRecordsByForm').getAt(a);
console.log(recStore);
},
mostly just trying some things but I can get the ID of the selected element from the combobox and that is where I am.
What I need is having the id to make a new query usign my AJAX api (PHP/SQL backend) and populate the grid with the info related with this id. In my case I have 1:M relations so when I pass the Id i expect M records which I want to render on the place of the old grid.
Thanks
Leron
Use filter() method. Provide information that you need to filter by and store object will automatically request updated info from the server (you already have remoteFilter configured).
Look at Ext.Ajax() to make an on-demand ajax call to the server-side to load up your data and then use Store.loadData() or something like that to re-populate the Grid.
I need to dynamically populate a form from fields in a database using EXT JS forms and ASP.NET MVC and I'm having trouble finding a starting point.
The database includes all of the settings: the field names, the field data types and the original field data. When a menu is clicked on the application's main page, the clicked item's settings should appear on a separate form. The data types include checkboxes, textfields, and possibly combo boxes.
I can easily return all of the settings in Json, but I know the form will need to iterate either with Ext.each or some other method, but I'm having trouble getting my head around this. I've also thought about using an Ext reusable type as a template that accepts Json data from the database to determine the field name, type and content.
something like this:
TextSettings = Ext.extend(Ext.Container, {
layout: 'column',
autoHeight: true,
autoWidth: true,
initComponent: function() {
this.items = [
{
xtype: 'container',
style: 'float:left;clear:left;',
items: [
{
xtype: 'label',
text: 'Setting Name',
style: 'display:block;',
ref: '../../../NameLabel'
},
{
xtype: 'label',
text: 'Setting description',
style: 'display:block;font-style:italic;',
ref: '../../../DescriptionLabel'
}
]
},
{
xtype: 'container',
style: 'float:right;clear:right;',
items: [
{
xtype: 'textfield',
width: 300,
ref: '../../../SettingEdit'
}
]
}
];
TextSettings.superclass.initComponent.call(this);
}
});
Does this look like a crash course?
Has anyone else done something similar?
I ran across this Ajax function online (probably the Sencha forums) and it seems to be working.
var ajax = Ext.Ajax.request({
url: '/Controller/Items',
method: 'get',
success: function (response) {
response = Ext.util.JSON.decode(response.responseText);
//form.add(Ext.decode(response.responseText).data);
for (i = 0; i < response.data.length; i++) {
form.add({
xtype: response.data[i].xtype,
fieldLabel: response.data[i].text,
name: response.data[i].name,
value: response.data[i].value,
style: response.data[i].style,
items: response.data[i].items,
width: response.data[i].width
});
}
form.doLayout();
}
});
With the following Json output:
{success: true, data: [{xtype: 'label', text: 'Report', style: 'display:block', ref: '../../../Displaylabel' },{xtype: 'label', text: \"Report Text\", style: 'display:block;font-style:italic;', ref: '../../../DescriptionLabel'},{xtype: \"textfield\", width: 300, ref: \"../../../SettingEdit\", value: \"A comment... for YOU!!!\"}, {xtype: 'checkbox', text: 'Check it for fun'}]}
Still more work to go, but this is at least giving me dynamic text fields.