Last active
July 1, 2020 16:12
-
-
Save rgdevment/a41a9167c2ff3982a362 to your computer and use it in GitHub Desktop.
[Paginación ExtJs] Permite crear una grilla con paginación desde ExtJs con PHP obteniendo datos desde una db en Oracle #ExtJs #PHP #Oracle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xtype: 'list', | |
itemId: 'MiListView', | |
store: 'MainStore', | |
masked: {xtype: 'loadmask', message: 'Cargando...'}, | |
plugins:[ | |
{ | |
xclass:'Ext.plugin.ListPaging', | |
autoPaging: false, | |
// These override the text; use CSS for styling | |
loadMoreText: 'Cargar más precauciones...', | |
noMoreRecordsText: 'Todas las precauciones fueron cargadas' | |
} | |
], | |
itemTpl: [ | |
'{OBSERVACION}' | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$current_page = 1; | |
$offset_page = 0; | |
$limit_per_page = 5; | |
$current_page = $_GET["page"]; | |
$limit_per_page = $_GET["limit"]; | |
$offset_page = $_GET["start"]; | |
$end = $offset_page + $limit_per_page + 5; | |
$query = $oracle->query("select * from | |
( select a.*, ROWNUM rnum from | |
(SELECT * FROM table | |
Where estado = 'A' | |
ORDER BY VENCE) a | |
where ROWNUM <= $end ) | |
where rnum >= $offset_page"); | |
$total = $oracle->query("SELECT cod FROM Vtable WHERE estado = 'A'"); | |
$dbresult = $query->all_to_json(); | |
$result = "{'success':true, 'items':" . $dbresult . ", 'total':" . $total->length() . "}"; | |
//Para jsonP | |
header("Access-Control-Allow-Origin: *"); | |
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); | |
$callback = $_REQUEST['callback']; | |
if ($callback) { //CON JSONP | |
header('Content-Type: text/javascript'); | |
echo $callback . '(' . json_encode($result) . ');'; | |
} else { //SIN JSONP | |
header("Content-Type: application/json; charset=UTF-8"); | |
echo $result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.define('com.store.Main', { | |
extend: 'Ext.data.Store', | |
requires: [ | |
'precauciones.model.Main', | |
'Ext.data.proxy.JsonP', | |
'Ext.data.reader.Json' | |
], | |
config: { | |
autoLoad: false, | |
model: 'com.model.Main', | |
storeId: 'MainStore', | |
clearOnPageLoad: false, | |
pageSize: 20, | |
proxy: { | |
//Para usar Ajax, no puede tener authentificación de usuario, | |
//esto se soluciona con htaccess, sin embargo es mejor usar el metodo | |
//jsonp, solo hay que agregar un callback en los PHP | |
type: 'jsonp', | |
url: 'lista.php', | |
reader: { | |
type: 'json', | |
rootProperty: 'items', | |
totalProperty: 'total' | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment