【发布时间】:2015-05-16 08:47:16
【问题描述】:
Extjs 5.0
在网格中,我有一个带有文本字段的收费栏,用于过滤网格(远程)。
工作正常。
但是,如果我使用数据库中不存在的单词(例如“mywxtyz”)进行过滤,则会出现错误:Ext.JSON.decode (): You're trying to decode an invalid JSON String,并且输出为空。
我想要的是当搜索没有返回任何记录(数据库中不存在)时,显示一个简单的消息或网格中的文本 emptyText,或在一个窗口中。
我该怎么做?
提前致谢。
我的代码:
onButtonFilter : function(button, newValue, oldValue, eOpts){
var me = this;
var textfield = Ext.ComponentQuery.query('#filter')[0];
var grid = Ext.ComponentQuery.query('#griditemId')[0];
var store = grid.getStore();
if (form.isValid()) {
store.proxy.extraParams = {
action : 'filterGrid',
name : textfield.getValue()
},
store.load();
}
}
我的 PHP 示例:
<?php
include("conexion.php");
$action = $_REQUEST['action'];
switch($action){
case "create":{
}
case "read":{
$start = $_REQUEST['start'];
$limit = $_REQUEST['limit'];
$statement = $conexao->stmt_init();
$sqlQuery = "SELECT name, email FROM contact LIMIT ?, ?";
$sqlTotal = "SELECT COUNT(name) as num FROM contact";
if(isset($_REQUEST['action']) AND $_REQUEST['action'] == 'filterGrid') {
$name = $_REQUEST['name'];
$sqlQuery = "SELECT name, email
FROM contact
WHERE name like '%$name%'
LIMIT ?, ?";
$sqlTotal = "SELECT COUNT(name) as num
FROM contact
WHERE name LIKE '%$name%'";
}
if ($statement = $conexao->prepare($sqlQuery)){
$statement->bind_param("ii", $start, $limit);
$statement->execute();
$statement->bind_result($col1, $col2);
while($statement->fetch()){
$output[] = array($col1, $col2);
};
if ($statement = $conexao->query($sqlTotal)){
$row = $statement->fetch_row();
$total = $row[0];
}
$sucess = array("success" => mysqli_errno($conexao) == 0);
echo json_encode(array(
"success" => $sucess,
"total" => $total,
"data" => $output
));
$conexao->close();
break;
}
case "update":{
}
case "destroy":{
}
}
?>
商店:
Ext.define('APP.store.StoreList', {
extend: 'Ext.data.Store',
itemId:'mystore',
model: 'SPP.model.ModelList',
pageSize: 25,
autoLoad:true,
autoLoad: {start: 0, limit: 25},
autoSync: false,
proxy: {
type: 'ajax',
actionMethods:{
create:'POST',
read:'POST',
update:'POST',
destroy:'POST'
},
api: {
create: 'php/crudActionList.php?action=create',
read: 'php/crudActionList.php?action=read',
update: 'php/crudActionList.php?action=update',
destroy: 'php/crudActionList.php?action=destroy'
},
reader: {
type: 'json',
rootProperty: 'data',
totalProperty:'total',
successProperty: 'success'
},
writer: {
type: 'json',
writeAllFields: true,
encode: true,
rootProperty: 'data'
}
},
});
【问题讨论】:
标签: extjs filter grid-layout