Related
I am using ExtJS 5.0.1. I have a grid which does not autoLoad. Once the store is manually loaded by using the click button in TopBar, the grid receives records.
I am trying to implement infinite scroll on this grid. My store has extra params that need to be passed to the backend in order to get the records. After the first page is loaded, for the second page, no extra params are passed to the backend. How can I correct this?
My store looks as follows ->
Ext.define('MyStore', {
// extend: 'Ext.data.BufferedStore',
extend: 'Ext.data.Store',
model : 'MyModel',
remoteSort: true,
buffered: true,
leadingBufferZone: 10,
trailingBufferZone: 10,
pageSize: 100,
proxy: {
type : 'rest',
format: 'json',
url : '/myApp/list',
extraParams: {
fromDate: '',
toDate: ''
},
reader: {
type: 'json',
rootProperty: 'data',
totalProperty: 'totalCount'
}
}
});
My Grid looks as follows-->
Ext.define('MyGridl', {
extend: 'Ext.grid.Panel',
requires: [
'MyStore'
],
layout: 'fit',
loadMask: true,
viewConfig: {
preserveScrollOnRefresh: true
},
initComponent: function() {
this.id = 'myGrid';
this.store = new MyStore();
this.callParent(arguments);
},
overflowY: 'auto',
frame: true,
columns: [{
xtype: 'rownumberer',
width: 50,
sortable: false
},{
text: 'Column1',
dataIndex: 'Col1',
flex: 1
},{
text: 'Column2',
dataIndex: 'Col2',
flex: 1
}
],
plugins: [
{
ptype: 'bufferedrenderer',
trailingBufferZone: 10,
leadingBufferZone: 10,
scrollToLoadBuffer: 10
}
],
tbar: {
items: [{
xtype : 'datefield',
id : 'fromDate',
emptyText: 'Enter From Date',
listeners : {
render : function(datefield) {
datefield.setValue(Ext.Date.add(new Date(), Ext.Date.DAY, -5));
}
}
},{
xtype : 'datefield',
id : 'toDate',
emptyText: 'Enter To Date',
listeners : {
render : function(datefield) {
datefield.setValue(new Date());
}
}
},{
xtype: 'button',
text: 'Filter by Date',
style: {
marginLeft: '15px'
},
scope: this,
handler: function(me){
var store = Ext.getStore('myStore'),
fromDay = me.up().down('#fromDate').getValue(),
toDay = me.up().down('#toDate').getValue();
store.removeAll();
store.load({
params:{
fromDate: fromDay,
toDate: toDay
}
});
}
}
]
}
});
I fixed this issue by adding
store.removeAll();
store.currentPage = 1;
store.getProxy().setExtraParam("fromDate", fromDay);
store.getProxy().setExtraParam("toDate", toDay);
store.load();
I'm trying to call a function from initComponent. However, I'm unable to get the scope of this object, thus running into ReferenceErrors.
The function I'm calling is getFileType and it's missing the scope and I'm unable to get it. (line nos: 204).
Is there a way to change scope inside the handler.
Also, by adding scope:this inside the button, I'm losing scope to pick the form data...
Any help here would be awesome!
Ext.define('D.application.component.de.AddConnectionPanel', {
extend: 'Ext.form.FieldSet',
initComponent : function()
{
var databaseConnDetails = Ext.create('Ext.form.Panel',{
bodyPadding: 15,
// width:'auto',
region:'center',
layout:{
align: 'center',
},
defaults: {
anchor: '100%',
},
title: 'Database Details',
items: [{
defaults: {
},
items: [{
readOnly: false,
hidden: false,
xtype: 'dsqcombobox',
name: 'DB_TYPE',
emptyText: 'DB Type',
flex: 1,
fieldID: 'Field-1',
}],
layout: 'hbox',
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_1',
},
{
defaults: {
},
items: [{
readOnly: false,
hidden: false,
xtype: 'dsqtextfield',
name: 'DB_URL',
emptyText: 'DB Url',
flex: 1,
fieldID: 'Field-2',
},
{
readOnly: false,
hidden: false,
xtype: 'dsqtextfield',
name: 'DB_PORT',
emptyText: 'DB Port',
flex: 1,
fieldID: 'Field-3',
}],
layout: 'hbox',
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_2',
},
{
defaults: {
},
items: [{
readOnly: false,
hidden: false,
xtype: 'dsqtextfield',
name: 'DB_SCHEMA',
emptyText: 'Schema Name',
flex: 1,
fieldID: 'Field-4',
},
{
readOnly: false,
hidden: false,
xtype: 'dsqtextfield',
name: 'DB_LABEL',
emptyText: 'Schema Label',
flex: 1,
fieldID: 'Field-6',
}],
layout: 'hbox',
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_4',
},
{
defaults: {
},
items: [{
readOnly: false,
hidden: false,
xtype: 'dsqtextarea',
name: 'DB_DESCRIPTION',
emptyText: 'Connection Description',
flex: 1,
fieldID: 'Field-6',
}],
layout: 'hbox',
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_6',
},
{
defaults: {
},
items: [{
readOnly: false,
hidden: false,
xtype: 'dsqtextfield',
name: 'DB_USERNAME',
emptyText: 'DB Username',
flex: 1,
fieldID: 'Field-5',
},
{
readOnly: false,
hidden: false,
xtype: 'dsqtextfield',
name: 'DB_PASSWORD',
inputType: 'password',
emptyText: 'DB Password',
flex: 1,
fieldID: 'Field-6',
}],
layout: 'hbox',
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_7',
},
{
defaults: {
},
items: [{
readOnly: true,
hidden: true,
xtype: 'dsqtextfield',
name: 'ID',
emptyText: 'Connection ID',
flex: 1,
fieldID: 'Field-6',
}],
layout: 'hbox',
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_8',
},
{
defaults: {
},
items: [{
readOnly: false,
hidden: false,
width:70,
xtype: 'dsqbutton',
name: 'save',
fieldLabel: 'Save',
fieldID:'Field-8',
}],
layout: {
type: 'hbox',
align: 'middle',
pack: 'center'
},
xtype: 'dsqfieldcontainer',
layoutID: 'Contain_9',
}],
xtype: 'dsqfieldset',
layoutID: 'Connection Details'
});
var fileConnDetails = Ext.create('Ext.form.Panel', {
bodyPadding:15,
defaults: {
anchor:'100%',
},
width:500,
title: 'File Details',
bodyPadding: 10,
frame: true,
renderTo: Ext.getBody(),
items: [{
xtype: 'filefield',
name: 'InputFile',
id:'filefield',
emptyText: 'File',
msgTarget: 'side',
allowBlank: false,
anchor: '100%',
buttonText: 'Browse...'
}],
buttons: [{
text: 'Upload',
layout:{
pack:'center',
align:'middle',
},
handler: function() {
var form = this.up('form').getForm(); // Get form details
if(form.isValid()){
var fileName = form.findField('filefield').getSubmitValue();
// Check to see if file type is supported
var retVal = getFileType(fileName);
if (retVal != DSQ_SUCCESS){
Ext.Msg.alert('Unsupported File Type');
return;
}
// Parse file and read data
retVal = parseInputFile(fileName, fileArray);
if (retVal != DSQ_SUCCESS) {
Ext.Msg.alert('Error! unable to read file');
return;
}
form.submit({
success: function(fp, action) {
Ext.Msg.alert('Success', 'Your file "' + action.result.file + '" has been uploaded.');
},
failure: function(fp, action) {
Ext.Msg.alert('Failed', 'File "' + action.result.file + '" upload failed');
}
});
}
}
}]
});
var connectionInfo = Ext.create('Ext.container.Container', {
autoEl:'div',
width:700,
bodyPadding: 5, // Don't want content to crunch against the borders
layout:'card',
items:[{
id:'file_card',
items:[fileConnDetails],
},{
id:'db_card',
items:[databaseConnDetails],
}],
});
var DataSourceOptionsContainer = Ext.create('Ext.container.Container',{
region:'center',
layout:{
type:'vbox',
align: 'center',
},
items : [{
xtype:'radiogroup',
vertical:false,
columns:2,
items: [{
boxLabel: 'Flat-File',
name:'datasource',
inputValue:'flatfile',
width:80,
checked:true,
},{
boxLabel: 'Database',
name:'datasource',
inputValue:'database',
width:80
}],
listeners: {
change: function(radiogroup, newVal, oldVal) {
var listenerObj = newVal.datasource;
switch(listenerObj) {
case 'database':
connectionInfo.getLayout().setActiveItem('db_card');
break;
case 'flatfile':
connectionInfo.getLayout().setActiveItem('file_card');
break;
default:
console.log("No such Object in connection group");
break;
}
}
}
}],
});
var config = {
items: [DataSourceOptionsContainer, connectionInfo]
};
Ext.apply(this,config);
this.callParent(arguments);
},
getFileType: function(fileName)
{
var fileTypesAllowed = [".csv", ".xls", ".xlsb"];
alert("File Type verification");
if(!Ext.Array.contains(fileTypesAllowed, fileName)) {
return 1;
}
return 1;
},
parseInputFile: function(fileName, fileArray)
{
return 1;
},
onRender : function()
{
this.callParent(arguments);
}
});
Store the reference to the form panel object in this instead of using a local variable:
this.fileConnDetails = Ext.create('Ext.form.Panel', {
(you'll also have to replace further references to that variable in initComponent with this.fileConnDetails)
Then, as you suggested, add scope: this to your button. You'll then have both the form panel and your functions in the same scope:
buttons: [{
text: 'Upload',
layout:{
pack:'center',
align:'middle',
},
handler: function() {
var form = this.fileConnDetails.getForm(); // Get form details
if(form.isValid()){
var fileName = form.findField('filefield').getSubmitValue();
// Check to see if file type is supported
var retVal = this.getFileType(fileName);
if (retVal != DSQ_SUCCESS){
Ext.Msg.alert('Unsupported File Type');
return;
}
// Parse file and read data
retVal = this.parseInputFile(fileName, fileArray);
if (retVal != DSQ_SUCCESS) {
Ext.Msg.alert('Error! unable to read file');
return;
}
form.submit({
success: function(fp, action) {
Ext.Msg.alert('Success', 'Your file "' + action.result.file + '" has been uploaded.');
},
failure: function(fp, action) {
Ext.Msg.alert('Failed', 'File "' + action.result.file + '" upload failed');
}
});
}
},
scope: this
}]
getFileType is part of your class. You need to add:
scope: this,
handler: function() {
// ....
this.getFileType();
}
You can see my code about grid.
Here, Window opens but there is not any value in my grid.
Could you please help?
My php returns JSON encode blow:
{"results":3,"disPath":"","success":"true","rows":[{"id":"1","faz":"Faz1"},{"id":"2","faz":"Faz2"},{"id":"3","faz":"Faz3"}]}
Code
Ext.define('MyDesktop.GridFazlar', {
extend: 'Ext.ux.desktop.Module',
requires: [
'Ext.data.ArrayStore',
'Ext.util.Format',
'Ext.grid.Panel',
'Ext.grid.RowNumberer'
],
id:'grid-fazlar',
init : function(){
this.launcher = {
text: 'Fazlar',
iconCls:'icon-grid'
};
},
createWindow : function(){
var desktop = this.app.getDesktop();
var win = desktop.getWindow('grid-fazlar');
if(!win){
var fazlarGridStore = new Ext.data.JsonStore({
root: 'rows',
autoLoad: true,
totalProperty: 'results',
remoteSort: true,
proxy: new Ext.data.HttpProxy({
url: 'phps/gridPhasesLoader.php',
actionMethods: {
create : 'POST',
read : 'POST',
update : 'POST',
destroy: 'POST'
},
}),
baseParams:{
depth: '2',
parentId: '2',
proccess: 'callGrid',
},
fields: [{
name :'id'
},{
name :'faz'
},
//{
]
});
win = desktop.createWindow({
id: 'grid-fazlar',
title:'Fazlar',
width:740,
height:480,
iconCls: 'icon-grid',
animCollapse:false,
constrainHeader:true,
layout: 'fit',
listeners:{
beforeshow: function(){
fazlarGridStore.proxy.extraParams = {
depth: '2',
parentId: '2',
proccess: 'callGrid',
};
}
},
items: [
{
border: false,
xtype: 'grid',
listeners: {
celldblclick : function() {
alert('Deneme');
},
},
contextMenu: new Ext.menu.Menu({
items:[
{
id:'grid-fazlar_menu_denemebutton',
text: 'DenemeButonu',
listeners: {
click: function(){
alert('sssss');
}
}
}
]
}),
store:fazlarGridStore,
columns: [
new Ext.grid.RowNumberer(),
{
text: "ID",
//flex: 1,
width: 70,
sortable: true,
dataIndex: 'id'
},{
text: "Faz",
//flex: 1,
width: 70,
sortable: true,
dataIndex: 'faz'
},
]
}
],
tbar:[{
text:'Add Something',
tooltip:'Add a new row',
iconCls:'add'
}, '-', {
text:'Options',
tooltip:'Modify options',
iconCls:'option'
},'-',{
text:'Remove Something',
tooltip:'Remove the selected item',
iconCls:'remove'
}]
});
}
return win;
},
statics: {
getDummyData: function () {
return [
['Faz1','06/06/2011','15/08/2010','19/12/2010'],
['Faz2','01/10/2010','15/11/2010','29/11/2011'],
['Faz3','16/11/2010','16/12/2010','14/02/2011'],
['Faz4','19/03/2011','20/03/2011','18/06/2011'],
['Faz5','21/03/2011','20/05/2011','18/08/2011'],
['Faz6','21/05/2011','05/07/2011','18/09/2011'],
['Faz7','06/07/2011','04/09/2011','06/12/2011'],
['Faz8','30/09/2011','30/10/2011','29/12/2011'],
];
}
}
});
Your Json has a custom root : 'rows'. You must configure your datareader to take this into account:
proxy: {
type: 'ajax',
url: 'phps/gridPhasesLoader.php',
actionMethods: {
create : 'POST',
read : 'POST',
update : 'POST',
destroy: 'POST'
},
reader: {
type: 'json',
root: 'rows'
}
},
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've encountered a problem with jqGrid datagrid.
I need to delete one row or more with a button "Delete".
Here my code:
$grid.navGrid('#pager', { edit: false, add: false, del: false, search: false });
$grid.navButtonAdd('#pager', {
caption: "Delete",
buttonicon: "ui-icon-del",
position: "last",
onClickButton: function() {
alert("Deleting Row");
row_ids = $grid.getGridParam('selarrrow');
$grid.delGridRow(row_ids, {
dataType: 'json',
mtype: 'GET',
url: '<?php echo $_SERVER['PHP_SELF'].'?app=my_app&action=record_delete'; ?>'
});
}
});
This snippet of code send to the "url:" option the id/s of selected row/s (it works).
That url return a response, in json format.. This answer say if the operation was successful or not.
I need to display an alert with that message, how do I do?
And, another problem, when I click on "Delete" button (on bottom of the jqGrid), it displays an ajax windows with the question "Do you want to delete selected items?", with the "Yes" input and the "No" input. When I click "Yes", this ajax window will not close!
Thank you!
Dante
EDIT [1] && [2]
$(document).ready(function()
{
$grid = $("#list");
fixPositionsOfFrozenDivs = function() {
if (typeof this.grid.fbDiv !== "undefined") {
$(this.grid.fbDiv).css($(this.grid.bDiv).position());
}
if (typeof this.grid.fhDiv !== "undefined") {
$(this.grid.fhDiv).css($(this.grid.hDiv).position());
}
};
$grid.jqGrid({
url: '<?php echo $_SERVER['PHP_SELF'].'?app=my_app&option=get_records'; ?>',
datatype: 'json',
mtype: 'GET',
height: 'auto',
width: window.innerWidth-35, //width: '1225',
colNames: ['ID', 'Column A', 'Column B', 'Column C', 'Column D'],
colModel: [
{ name: 'id', index: 'id', width: 130, align: 'center', search: true,
sortable: true, frozen: true, editable: true, edittype: 'text', formatter: 'showlink',
editoptions: { size: 130, maxlength: 50 }, stype: 'text' },
{ name: 'col_a', index: 'col_a', width: 250, align: 'left', search: true,
sortable: true, frozen: false, editable: true, edittype: 'text',
editoptions: { size: 250, maxlength: 40 }, stype: 'text' },
{ name: 'col_b', index: 'col_b', width: 120, align: 'left', search: true,
sortable: true, frozen: false, editable: true, edittype: 'text',
editoptions: { size: 120, maxlength: 40 }, stype: 'text' },
{ name: 'col_c', index: 'col_c', width: 100, align: 'right', search: true,
sortable: true, frozen: false, editable: true, edittype: 'text',
editoptions: { size: 100, maxlength: 40 }, stype: 'text' },
{ name: 'col_d', index: 'col_d', width: 100, align: 'right', search: true,
sortable: true, frozen: false, editable: true, edittype: 'text',
editoptions: { size: 100, maxlength: 6 }, stype: 'text' }
],
caption: 'Objects',
pager: '#pager',
sortname: 'id',
sortorder: 'ASC',
rowNum: 25,
rowList: [25, 50, 100, 200, <?php echo $totrecords; ?>],
loadonce: true,
gridview: true,
viewrecords: true,
rownumbers: true,
rownumWidth: 40,
toppager: true,
multiselect: true,
autoencode: true,
ignoreCase: true,
shrinkToFit: false,
loadComplete: function() {
$("option[value=<?php echo $totrecords; ?>]").text('All');
},
editurl: '<?php echo $_SERVER['PHP_SELF'].'?app=my_app&option=delete_records'; ?>'
});
$grid.jqGrid('filterToolbar', {multipleSearch: false, stringResult: false, searchOnEnter: false, defaultSearch: 'cn'});
$grid.navGrid('#pager', { edit: false, add: false, del: false, search: false });
$grid.navButtonAdd('#pager', {
caption: "Delete",
buttonicon: "ui-icon-del",
position: "last",
onClickButton: function() {
row_ids = $grid.getGridParam('selarrrow');
$grid.delGridRow(row_ids, {
closeOnEscape: true,
mtype: 'POST',
afterSubmit: function(data_from_server, array_data) {
var result = data_from_server.responseText;
var message = eval('(' + result + ')');
alert(message.query);
}
});
}
});
$grid.jqGrid('setFrozenColumns');
$grid[0].p._complete.call($grid[0]);
fixPositionsOfFrozenDivs.call($grid[0]);
});
You should be able to use the afterSubmit event to display your message. From the jqGrid documentation:
afterSubmit
fires after response has been received from server. Typically used to display status from server (e.g., the data is successfully deleted or the delete cancelled for server-side reasons). Receives as parameters the data returned from the request and an array of the posted values of type id=value1,value2.
When used this event should return array with the following items [success, message]
where success is a boolean value if true the process continues, if false a error message appear and all other processing is stopped.
afterSubmit : function(response, postdata)
{
…
return [succes,message]
}
Regarding your second problem, I am not sure why the Ajax window will not close. Have you debugged the code to see if you are receiving a JavaScript error at that time? If not, it may be necessary for you to post a small example demonstrating the problem.
It's not good to use HTTP GET for delete operation. Do you want that the previous server response on the same URL will be cached and not send to the server? Default value of mtype is 'POST'. If you have RESTfull services on the server side you will need to use mtype: 'DELETE', but the usage of 'GET' can have sense only for the some dummy code which don't delete anything on the server.
Moreover you use dataType: 'json' parameter which is not exist for delGridRow (see the documentation). Even if you would use ajaxDelOptions: { datyType: "json" } you will get the server response (see the answer of Justin) not automatically converted from JSON to object. The reason is that the current code of delGridRow use complete callback instead of success callback (see here). So if you get JSON response from the server you will have to call $.parseJSON explicitly inside of afterSubmit callback (see the Justin's answer).