jqGrid删除最后一条记录时出错

时间:2017-03-13 06:48:46

标签: jqgrid

删除PHP 5.5.9的最后一条记录时出错

colModel: [
    {
        name: '',
        formatter: 'actions',
        formatoptions: {
            keys: true,
            afterSave: function () {
                $('#table_grid').trigger('reloadGrid');
            }
        }
    }
],          

loadComplete:function(data)
{
    alert(data.records);

    //PHP 5.3.13  $responce->records = 0
    //PHP 5.5.9  error empty    
}

有什么不对,帮助

1 个答案:

答案 0 :(得分:0)

我使用jquery.jqGrid.min 5.2.0

<script type="text/javascript">
$(document).ready(function()
{
    $('#table').jqGrid(
    {
        mtype:'POST',
        datatype:'json',
        url:'data.php',
        editurl:'data.php',
        rowNum:50,
        pager:'#pager',
        colModel:[
            {name:'action',formatter:'actions',formatoptions:{keys:true,afterSave:function(){$('#table').trigger('reloadGrid');}}},
            {name:'name',editable:true}
        ],
        loadComplete:function(data)
        {
            if(data.records >= 0)//error if PHP 5.5.9
            { 
            }
            //If i use PHP 5.3.13 function returns 0 (deletes the last record)
            //If i use PHP 5.5.9 function nothing returns (Do not delete the last record)               
        }
    });
    $('#table').jqGrid('inlineNav','#pager',{edit:false,addtext:'ADD',savetext:'SAVE',canceltext:'CANCEL',addParams:{position:'last',addRowParams:{keys:true,aftersavefunc:function(){$('#table').trigger('reloadGrid');}}}});
});
</script> 

//reading data.php
$page = $_POST['page'];
$limit = $_POST['rows'];

$count = $db->query('SELECT COUNT(*) FROM siri')->fetchColumn();

if($count > 0){$total_pages = ceil($count/$limit);}else{$total_pages = 0;}
if($page > $total_pages){$page = $total_pages;}
$start = $limit*$page-$limit;
if($start < 0){$start = 0;}

$res = $db->query('SELECT id, name FROM siri LIMIT '.$start.', '.$limit);

$i=0;
while($row = $res->fetch(PDO::FETCH_ASSOC))
{
    $return->rows[$i]['id'] = $row['id'];
    $return->rows[$i]['cell'] = array('',$row['name']);
$i++;
}

$return->page = $page;
$return->total = $total_pages;
$return->records = $count;

echo json_encode($return);

//Deleting data.php 
$id = (int)$_POST['id'];
$db->exec('DELETE FROM siri WHERE id = '.$id);  

一切正常,jqGrid很好

但如果我使用PHP 5.5.9

浏览器中的最后一项不会被删除

页面更新后,它会消失

要删除,我使用内联操作

但如果我使用PHP 5.3.13没有错误一切都很好

我非常需要PHP 5.5.9