I have a paging toolbar implemented in my grid using extjs 4.1 I get 20 sets of record of first page. "but" when I click next, it does not show the next page. I figure the problem is here
proxy: {
type: 'ajax',
scope: this,
url: 'Controller/getData',
extraParams: {
PageNumber: this.currentPage, // this doesn't change on clicking next
PageSize: 20
},
reader: {
type: 'json',
root: 'myTable',
totalProperty: 'count'
}
as you can see, the PageNumber I am passing to my controller is static.. If I change that to whatever number I get that page... so how do I get the current page so that I can pass it to my controller..
below is my toolbar
bbar: Ext.create('Ext.PagingToolbar', {
scope: this,
store: myStore,
displayInfo: true,
displayMsg: 'Displaying Records {0} - {1} of {2}',
emptyMsg: "No Records to display"
})
please help... thanks
I'm not sure if I can help you, have you check your backend processing code? I mean, as far as I know, the way you declare store and paging toolbar is right so maybe the problem exist at server side.
for a reference, this is my server side page (remote/data/user/mahasiswa/read.php) to handle store with paging support:
$sql = "SELECT * FROM user";
$rs = mysql_query($sql);
$totalCount = mysql_num_rows($rs);
$sql = $sql." LIMIT ".$start.",".$limit;
$rs = mysql_query($sql);
while($obj = mysql_fetch_object($rs)){
$arr[] = $obj;
}
echo '{success:true, totalCount:'.$totalCount.', data:'.json_encode($arr).'}';
then, this is my store:
Ext.define('PMK.store.user.Mahasiswa', {
extend: 'Ext.data.Store',
model: 'PMK.model.user.Mahasiswa',
pageSize: 30,
proxy: {
type: 'ajax',
url: 'remote/data/user/mahasiswa/read.php',
reader: {
type: 'json',
root: 'data',
successProperty: 'success',
totalProperty: 'totalCount'
}
})
finally this is my view:
Ext.define('PMK.view.user.mahasiswa.List' ,{
extend: 'Ext.panel.Panel',
alias : 'widget.mhslist',
title:'Manage Mahasiswa',
layout:'fit',
initComponent: function() {
this.items = [
{
xtype:'grid',
store:'user.Mahasiswa',
columns: [
{xtype: 'rownumberer', width: 50, sortable: false},
{header: 'Angkatan', dataIndex: 'ANGKATAN', sortable:true, width:60},
{header: 'NIM', dataIndex: 'NIM', sortable:true, width:100},
{header: 'Nama', dataIndex: 'NAMA', sortable:true, width:225},
{header: 'Program Studi', dataIndex: 'PRODI', sortable:true, width:225},
{header: 'Kelas', dataIndex: 'KELAS', sortable:true, width:50},
{header: 'Dosen PA', dataIndex: 'DOSEN_PA', sortable:true, width:125},
{header: 'Jalur', dataIndex: 'JALUR', sortable:true, width:50},
{header: 'Asal Sekolah', dataIndex: 'ASAL_SEKOLAH', sortable:true, width:175},
{header: 'Tempat Lahir', dataIndex: 'TL', sortable:true, width:100},
{header: 'Tanggal Lahir', dataIndex: 'TGL', sortable:true, width:75},
{header: 'JK', dataIndex: 'JK', sortable:true, width:25},
{header: 'Alamat', dataIndex: 'ALAMAT', sortable:true, width:225},
{header: 'Email', dataIndex: 'EMAIL', sortable:true, width:130},
{header: 'Telp', dataIndex: 'TELP', sortable:true, width:100},
{header: 'Agama', dataIndex: 'AGAMA', sortable:true, width:50},
{header: 'Input Date', dataIndex: 'INPUT_DATE', sortable:true, width:125},
{header: 'Input By', dataIndex: 'INPUT_BY', sortable:true, width:125},
{header: 'Edit Date', dataIndex: 'EDIT_DATE', sortable:true, width:125},
{header: 'Edit By', dataIndex: 'EDIT_BY', sortable:true, width:125}
]
}
];
this.bbar = Ext.create('Ext.PagingToolbar', {
store: 'user.Mahasiswa',
displayInfo: true,
displayMsg: 'Displaying mahasiswa {0} - {1} of {2}',
emptyMsg: "No mahasiswa to display"
});
this.callParent(arguments);
}
});
Related
I make an ajax request to the servlet that returns the result of a database query.
I can see with firebug the response and I want to put these results in a list (or other..) that I have already created.
I tried to read this post but it didn't help me..
Code:
this is the ajax request:
Ext.Ajax.request({
url: '/VIProject/Container',
success: function (action){alert('Lista caricata!'); console.debug(action); },
failure: function (){alert('Errore nel caricamento...');},
headers: {
'my-header': 'foo'
},
params: { action: "GETCONTAINERLIST" }
});
response from servlet(firebug):
{"message":"OK","container":[{"idOrdine":"1","numLotto":"123"},{"idOrdine":"2","numLotto":"321"},{"idOrdine":"3","numLotto":"876"}],"success":true}
list:
var listView = Ext.create('Ext.grid.Panel', {
width:425,
height:250,
id: 'lista',
collapsible:true,
title:'Simple ListView <i>(0 items selected)</i>',
store: //???
multiSelect: true,
viewConfig: {
emptyText: 'No images to display'
},
columns: [{
text: 'idOrdine',
flex: 15,
sortable: true,
dataIndex: 'idOrdine'
},{
text: 'Last Modified',
flex: 20,
sortable: true,
dataIndex: 'numLotto'
}]
});
How can I do?
I've modified your code to use a store:
Ext.define('MyModel', {
extend: 'Ext.data.Model',
fields: ['idOrdine', 'numLotto']
})
var listView = Ext.create('Ext.grid.Panel', {
width:425,
height:250,
id: 'lista',
collapsible:true,
title:'Simple ListView <i>(0 items selected)</i>',
store: store: {
model: MyModel,
autoLoad: true,
proxy: {
type: 'ajax',
url: '/VIProject/Container',
reader: {
type: 'json',
root: 'container'
}
}
},
multiSelect: true,
viewConfig: {
emptyText: 'No images to display'
},
columns: [{
text: 'idOrdine',
flex: 15,
sortable: true,
dataIndex: 'idOrdine'
},{
text: 'Last Modified',
flex: 20,
sortable: true,
dataIndex: 'numLotto'
}]
});
Even in this way it works:
var proxy=new Ext.data.HttpProxy({url:'/VIProject/Container'});
var reader=new Ext.data.JsonReader({},[
{name: 'idOrdine', mapping: 'idOrdine'},
{name: 'numLotto', mapping: 'numLotto'}
]);
var store=new Ext.data.Store( {
proxy:proxy,
reader:reader
});
store.load();
I tried in every way.. but i don't know what to do!
I'm new to jqgrid finally i've setup a grid. Suppose i need to setup jsonReader so that the grid knows where to get my grid-data in the json return. However i got blank cells after trying for days.
Here is my grid:
jQuery("#list48").jqGrid({
url: 'dbtest.aspx/get_offsite_history2',
datatype: "json",
mtype: 'POST',
ajaxGridOptions: { contentType: "application/json" },
serializeGridData: function(postData) {
return JSON.stringify(postData);
},
jsonReader: {
root: function(obj) { alert(JSON.stringify(obj.d)); return obj.d; },
repeatitems: false
},
height: 'auto',
rowNum: 30,
rowList: [10, 20, 30],
colNames: ['name', 'start_date', 'duration', 'offsite_cat'],
colModel: [
{ name: 'name', index: 'name', width: 80, align: 'left', editable: true, edittype: 'text' },
{ name: 'start_date', index: 'start_date', width: 120, align: 'left', editable: true, edittype: 'text' },
{ name: 'duration', index: 'duration', width: 120, align: 'left', editable: true, edittype: 'text' },
{ name: 'offsite_cat', index: 'offsite_cat', width: 120, align: 'left', editable: true, edittype: 'text'}],
pager: "#plist48",
viewrecords: true,
sortname: 'name',
caption: "Grouping Array Data",
gridview: true
});
This is the server return from url dbtest.aspx/get_offsite_history2:
{"d":"[{\"name\":\"A\",\"start_date\":\"B\",\"duration\":\"C\",\"offsite_cat\":\"D\"}]"}
i suppose to get the result by setting "root: 'd'" but i got 64 blank rows for that...
look for comments... many thanks
The reason of your problem is the bug in your server code. You make serialization to JSON twice. After deserializing of d property of the server response you get still JSON string (!!!) instead of object. Typical error is manual usage of JavaScriptSerializer.Serialize in the web method. One should return the object itself instead of the string which is the result of serializing.
Without modifying of your current server code you can fix the problem by usage of
jsonReader: {
root: function (obj) {
alert(typeof obj.d === "string" ? obj.d : JSON.stringify(obj.d));
return typeof obj.d === "string" ? $.parseJSON(obj.d) : obj.d;
},
repeatitems: false,
page: function () { return 1; },
total: function () { return 1; },
records: function (obj) {
return typeof obj.d === "string" ? $.parseJSON(obj.d).length : obj.length;
}
}
or (if you use loadonce: true) just
jsonReader: {
root: function (obj) {
return typeof obj.d === "string" ? $.parseJSON(obj.d) : obj.d;
},
repeatitems: false
}
Because your current server code seems not implemented the paging of data you should increase rowNum to some large enough value like rowNum: 10000 or to use loadonce: true.
UPDATED: You can find here modified demo which works. It displays
after the alert message.
I think the problem is the structure of your returned json data.
Below is one that I use :
{ "page":1,
"rows":[{"id":"1","cell":["1","1","Row 1","3","9",""]},
{"id":"2","cell":["2","2","Row 2","2","1",""]},
{"id":"3","cell":["3","4","Row 3","2","0",""]}],
"records":3,
"total":1
}
You may need to add a colModel for id to uniquely identify each row.
e.g.
colNames: ['id', 'name', 'start_date', 'duration', 'offsite_cat'],
colModel: [
{ name: 'id', index: 'id', hidden: true },
{ name: 'name', index: 'name', width: 80, align: 'left', editable: true, edittype: 'text' },
{ name: 'start_date', index: 'start_date', width: 120, align: 'left', editable: true, edittype: 'text' },
{ name: 'duration', index: 'duration', width: 120, align: 'left', editable: true, edittype: 'text' },
{ name: 'offsite_cat', index: 'offsite_cat', width: 120, align: 'left', editable: true, edittype: 'text'}],
Hope that helps.
Hii Guys!!!
I made jqgrid in which i added a FilterToolbar.Now as per my need i need dropdownmenu for unique values in FilterToolbar column.I am using asp.net...
Here is my code...
$(function () {
$("#UsersGrid").jqGrid({
url: 'jqGridHandler.ashx',
datatype: 'json',
height: 250,
colNames: ['UserID', 'UserName', 'FirstName', 'MiddleName', 'LastName', 'EmailID'],
colModel: [
{ name: 'UserID', index: 'UserID', width: 100, sortable: true },
{ name: 'UserName', width: 100, sortable: true },
{ name: 'FirstName', width: 100, sortable: true },
{ name: 'MiddleName', width: 100, sortable: true },
{ name: 'LastName', width: 100, sortable: true },
{ name: 'EmailID', width: 150, sortable: true }
],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#UsersGridPager',
sortname: 'UserID',
viewrecords: true,
sortorder: 'asc',
autowidth:true
//caption: 'JSON Example'
});
$("#UsersGrid").jqGrid('navGrid', '#UsersGridPager', { edit: false, add: false, del: false });
$("#UsersGrid").jqGrid('filterToolbar', { stringResult: true, searchOnEnter:true, defaultSearch: 'cn' });
$("#UsersGrid").jqGrid('navButtonAdd', '#UsersGrid-pager', { caption: "Filter", title: "Toggle Searching Toolbar", buttonicon: 'ui-icon-pin-s', onClickButton: function () { $("#UsersGrid")[0].toggleToolbar(); }
});
Plz guys help me to get the solution..
Thanx in advance....
The easiest way is the usage stype: "select". If you want fill dropdown with unique value from the column you can do this either on the server side or on the client side. If you provide all possible the unique values on the server side in form HTML fragment of <select> you can specify dataUrl option of searchoptions (or editoptions). If you provide the data on the client side you can specify value property of searchoptions (or editoptions) instead. In the answer you will find the example of possible implementation.
I hope this is my last question of today. I found a nice actioncolumn option in designer 2. I add one to my grid and it looks like this:
xtype: 'gridpanel',
title: 'Reports',
forceFit: true,
store: 'ReportsStore',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'Name',
text: 'Name'
},
{
xtype: 'gridcolumn',
dataIndex: 'Type',
text: 'Type'
},
{
xtype: 'gridcolumn',
dataIndex: 'Description',
text: 'Description'
},
{
xtype: 'actioncolumn',
dataIndex: 'Name',
items: [
{
handler: function(view, rowIndex, colIndex, item, e) {
console.log(row, col);
},
altText: 'Run report',
iconCls: 'runReport'
}
]
}
],
viewConfig: {
},
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'tbfill'
},
{
xtype: 'button',
iconCls: 'addReport',
text: 'Add report',
listeners: {
click: {
fn: me.onButtonClick,
scope: me
}
But there is nothing happening. What i want is that there is an button/icon and when you click on it it will open a ext.window with the reportId from that row. I can't find how i do this with designer.
I don't see an icon now so there is nothing yet to click on. What do i miss?
Thanks,
TJ
You miss listener for this button:
add something like that into your item definition:
handler: function(grid, row, col) {
console.log(row, col);
}
I was able to put a dijit.form.DateTextBox and a dijit.form.ComboBox in a dojox.grid.DataGrid but not a dijit.form.Button. I have not tried with other widgets.
new dojox.grid.DataGrid({
store: new dojo.data.ItemFileReadStore({data: {items: [{option: 'option A', date:'10/31/2011'},{option: option B'}]}}),
structure:[{
field: "option",
editable: true,
type: dojox.grid.cells._Widget,
widgetClass: dijit.form.ComboBox,
widgetProps: {
store: new dojo.data.ItemFileReadStore({data: {items: [{option: 'option A'},{position: option B'}]}}),
searchAttr: 'option'
},{
field: 'date',
editable: true,
type: dojox.grid.cells.DateTextBox,
widgetProps: {selector: "date"},
formatter: function(v) {if (v) return dojo.date.locale.format(new Date(v),{selector: 'date'})}
},{
field: "button",
type: dojox.grid.cells._Widget,
editable: true,
widgetClass: dijit.form.Button,
widgetProps: {style: {width: "100px"},label: "dijit button?"}
}]
})
Salu2,
Jose Leviaguirre
It seems that since 1.4, the grid can handle dijits via formatter
{
field: "button",
type: dojox.grid.cells._Widget,
editable: false,
formatter: function(){
return new dijit.form.Button({label:"test"})
}
Here is working sample solution: http://jsfiddle.net/jleviaguirre/u3QFj/5/