A ver si alguien puede ayudarme...
Tengo el siguiente código y me gustaría que los resultados se paginaran de 1 en 1.
El caso es que la barra de páginas muestra la información correcta, pero lo que son los datos no se paginan en si. Es decir, tengo 5 registros en la tabla, en la barra aparecen página 1 de 5, pero los 5 registros se muestran en la 1ª página y según vas avanzando la información no cambia...
Soy nueva en ExtJS y por muchas vueltas que le doy, no encuentro dónde puede estar el problema...
Agradezco de antemano su atención y les dejo mi código. Un saludo.
- Código: Seleccionar todo
Ext.ns("com.quizzpot.tutorials");
com.quizzpot.tutorials.Crud = {
init : function() {
//CRUD
var proxy = new Ext.data.HttpProxy({
api: {
read : "serverside/getContacts.php",
create : "serverside/createContact.php",
update : "serverside/updateContact.php",
destroy : "serverside/destroyContact.php"
}
});
var rd_random_employee_data = new Ext.data.JsonReader({}, ['idprovincia', 'descprovincia']);
var provincias = new Ext.data.Store({
reader: new Ext.data.JsonReader({
fields: ['idprovincia', 'descprovincia'],
root: 'rows'}),
proxy: new Ext.data.HttpProxy({
url: 'serverside/getProvincias.php'
}),
});
provincias.load();
var provin = new Ext.form.ComboBox({
store: provincias,
valueField: 'idprovincia',
displayField: 'descprovincia',
mode: 'remote',
minChars : 0
});
var reader = new Ext.data.JsonReader({
totalProperty : 'total',
successProperty : 'success', //<--- el successproperty indica la propiedad que define si se ha insertado/actualizado o borrado con éxito
messageProperty : 'message',
idProperty : 'coddelegacion',
root : 'data' //<--- este es el nombre del parámetro que llega al servidor con el JSON modificado
},[
{name: 'descdelegacion', allowBlank: false},
{name: 'domiciliodelegacion', allowBlank: false},
{name: 'poblaciondelegacion', allowBlank: false},
{name: 'emaildelegacion', allowBlank: false},
{name: 'telefonodelegacion', allowBlank: false},
{name: 'faxdelegacion', allowBlank: false},
{name: 'codpostaldelegacion', allowBlank: false},
{name: 'provinciadelegacion', allowBlank: false}
]);
var writer = new Ext.data.JsonWriter({
encode : true,
writeAllFields : true //<--- decide si se manda al servidor solamente los campos modificados o todos
});
this.storeGrid = new Ext.data.Store({
id : "id",
proxy : proxy,
reader : reader,
writer : writer,
autoSave : true //<--- hace las peticiones al servidor automáticamente
});
var textFieldEmail = new Ext.form.TextField({vtype: "email",allowBlank: false}),
textFieldDelegacion = new Ext.form.TextField({allowBlank: false}),
textFieldDomicilio = new Ext.form.TextField({allowBlank: false}),
textFieldPoblacion = new Ext.form.TextField({allowBlank: false}),
sm = new Ext.grid.CheckboxSelectionModel();
var textFieldTelefono = new Ext.form.TextField({
width: 80,
allowBlank:false,
maskRe : /['0-9'.-]$/,
plugins: [new Ext.ux.InputTextMask({
mask:'999-999999',
clearInvalid:false
})]
});
var textFieldFax = new Ext.form.TextField({
width: 80,
allowBlank:false,
maskRe : /['0-9'.-]$/,
plugins: [new Ext.ux.InputTextMask({
mask:'999-999999',
clearInvalid:false
})]
});
var textFieldCP = new Ext.form.TextField({
width: 60,
allowBlank:false,
maskRe : /['0-9'.-]$/,
plugins: [new Ext.ux.InputTextMask({
mask:'99999',
clearInvalid:false
})]
});
var pag = new Ext.PagingToolbar({
store:this.storeGrid
,displayInfo:true
,pageSize:1
});
this.grid = new Ext.grid.EditorGridPanel({
store : this.storeGrid,
columns : [
sm,
{header:'Delegación', dataIndex:'descdelegacion',width:180,sortable: true, editor:textFieldDelegacion},
{header:'E-mail', dataIndex:'emaildelegacion',sortable: true,width:180,editor:textFieldEmail},
{header:'Domicilio', dataIndex:'domiciliodelegacion',sortable: true,width:150, editor:textFieldDomicilio},
{header:'Población', dataIndex:'poblaciondelegacion',sortable: true,width:150, editor:textFieldPoblacion},
{header:'Cod.Postal', dataIndex:'codpostaldelegacion',sortable: true,width:60, editor:textFieldCP},
{header:'Teléfono', dataIndex:'telefonodelegacion',sortable: true,width:70, editor:textFieldTelefono},
{header:'Fax', dataIndex:'faxdelegacion',sortable: true,width:70, editor:textFieldFax},
{header:'Provincia', dataIndex:'provinciadelegacion',sortable: true,width:90, editor:provin}
],
sm : sm,
border : false,
stripeRows : true,
bbar: pag,
clicksToEdit: 1
});
this.storeGrid.load({params: {start:0, limit: 1}});
this.grid.on('afteredit',this.aviso);
var win = new Ext.Window({
title : "eProject - Gestión Delegaciones",
layout : "fit",
tbar : [
{text:'Añadir Delegación', scope:this, handler:this.addContact,iconCls:'save-icon'},
{text:"Eliminar Selección", scope:this, handler:this.onDelete,iconCls:'delete-icon'},
{text:"Exportar", scope:this, handler:this.exportPDF,iconCls:'pdf-icon'},
{text:"Exportar", scope:this, handler:this.exportExcel,iconCls:'excel-icon'}
],
width : 1000,
height : 300,
items : [this.grid]
});
win.show();
},
aviso: function()
{
alert("aviso");
},
onLoad : function()
{
alert("guarda");
},
onDelete : function(){
var rows = this.grid.getSelectionModel().getSelections();
if(rows.length === 0){
return false;
}
this.storeGrid.remove(rows);
Ext.MessageBox.alert('eProject','Registro(s) Eliminado(s) Con Éxito');
},
addContact : function(){
var contact = new this.storeGrid.recordType({
delegacion : "",
domicilio : "",
poblacion : "",
email : "",
cp: "",
telefono: "",
fax: "",
provincia: "",
});
this.grid.stopEditing();
this.storeGrid.insert(0,contact);
this.grid.startEditing(0,1);
},
exportPDF: function(){
var rows = this.grid.getSelectionModel().getSelections();
var nSeleccionados = rows.length;
var nElementos = this.storeGrid.getCount();
var seleccionados = new Array();
if(rows.length === 0){
Ext.MessageBox.alert('eProject','No Ha Seleccionado Nada');
return false;
}
var i = 0;
while (i<nSeleccionados)
{
seleccionados[i]=rows[i].id;
i=i+1;
}
location.href="listado-delegaciones-sel.php?seleccion="+seleccionados;
},
exportExcel: function(){
alert("exportar a Excel");
}
}
Ext.onReady(com.quizzpot.tutorials.Crud.init,com.quizzpot.tutorials.Crud);
Y getContacts.php
- Código: Seleccionar todo
<?php
$connection= mysql_connect("localhost","kszwsoso_ugespro","ugespro") or die("Connection Failed".mysql_error());
mysql_select_db("kszwsoso_gestorproyectos",$connection)or die("Error loading the DataBase".mysql_error());
//$result= mysql_query("SELECT * FROM gestdelegaciones001");
$result= mysql_query("SELECT coddelegacion,descdelegacion,domiciliodelegacion,poblaciondelegacion,provinciadelegacion,descprovincia,codpostaldelegacion,telefonodelegacion,faxdelegacion,emaildelegacion FROM gestdelegaciones001,gestprovin001 WHERE gestdelegaciones001.provinciadelegacion=gestprovin001.idprovincia");
$data= array();
$metadata = array();
while($row= mysql_fetch_array($result)){
array_push($data,array(
"coddelegacion" => $row["coddelegacion"],
"descdelegacion" => $row["descdelegacion"],
"domiciliodelegacion" => $row["domiciliodelegacion"],
"poblaciondelegacion" => $row["poblaciondelegacion"],
"provinciadelegacion" => $row["provinciadelegacion"],
"codpostaldelegacion" => $row["codpostaldelegacion"],
"telefonodelegacion" => $row["telefonodelegacion"],
"faxdelegacion" => $row["faxdelegacion"],
"emaildelegacion" => $row["emaildelegacion"],
));
}
echo json_encode(
array(
"success" => true,
"data" => $data
));

