Jqgrid冻结多用户

时间:2014-02-26 08:50:41

标签: jqgrid jqgrid-php

我一直在使用Jqgrid为多用户(超过70人)制作一个应用程序。当只有一个人使用它时,网格可以在localhost甚至服务器上运行,但只要有几个人登录,应用程序停止为除一个人以外的所有人随机加载。当一个人完成他的行动而另一个人重新加载页面时,情况恢复正常。 这是我的代码: 我到处都看,但似乎我是唯一一个遇到这个问题的人。 提前谢谢。

$("#list").jqGrid({
    url: 'include/configacompte.php', 
    editurl:"include/editacompte.php",
    datatype: "xml",
   mtype: "GET",
   postData:{idagenceco: "<?php echo $_SESSION['idAgence'] ?>" },
   colnames : [...]
    pager: jQuery("#pager"),
    rowNum: 100,
    rowList: [100, 200, 300],
    autowidth: true,
    sortname: "numSemaine",
    sortorder: "asc",
    viewrecords: true,
    gridview: true,
    autoencode: true,
     onSelectRow: function(id){
    if(id && id!==lastsel2){
        $('#list').jqGrid('restoreRow',lastsel2);
        $('#list').jqGrid('editRow',id,true,'','','','',reload);
        lastsel2=id;

            }
},
    multiboxonly:true,
    multiselect: true,
    loadonce : true, 
    scroll:1,
    height:500,
    ignoreCase:true,
    caption: "Gestion des Acomptes"        

});

 function reload() {
  window.location.reload();
};


$("#list").jqGrid('filterToolbar',{stringResult: true,searchOperators : true,searchOnEnter:true});

$("#list").jqGrid('getGridParam','url');



$("#list").jqGrid('navGrid','#pager',{edit:false,add:false,refresh:false},
                {/* reloadAfterSubmit: true, closeAfterAdd: true, closeAfterEdit: true, closeAfterSubmit: true*/ }, // default settings for edit
                {/*closeAfterAdd: true*/ }, // default settings for add
                { url: 'include/editacompte.php',
                     onclickSubmit: function (options, postdata) {
                    alert('Enregistrement(s) supprimé(s)');
                    return { myData: 'Hello'};
                }
                }, // delete instead that del:false we need this
                {seOnEscape: true, closeAfterSearch: true}, // search options
                {} /* view parameters*/
               );




$("#list").jqGrid('inlineNav',"#pager",{addParams: {
    useDefValues: true,
    position :"first",
    addRowParams:{keys:true,aftersavefunc:reload}
    }},
{},// edit  
{}//add
);



$("#list").jqGrid('sortableRows');



});

configacompte.php

<?php 

//include the information needed for the connection to MySQL data base server. 
// we store here username, database and password 
include("dbconfig.php");
//include("phptest.php");

// to the url parameter are added 4 parameters as described in colModel
// we should get these parameters to construct the needed query
// Since we specify in the options of the grid that we will use a GET method 
// we should use the appropriate command to obtain the parameters. 
// In our case this is $_GET. If we specify that we want to use post 
// we should use $_POST. Maybe the better way is to use $_REQUEST, which
// contain both the GET and POST variables. For more information refer to php         documentation.
// Get the requested page. By default grid sets this to 1. 

$page = $_GET['page']; 

// get how many rows we want to have into the grid - rowNum parameter in the grid 
$limit = $_GET['rows']; 
//$limit = isset($_POST['rows'])? $_POST['rows']:100; 
// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel 
$sidx =$_GET['sidx']; //$_REQUEST['sidx']; 

// sorting order - at first time sortorder 
$sord = $_GET['sord']; // $_GET['sord']; 
//$idagenceco = $_GET['idagenceco'];*/

$idagenceco=$_GET['idagenceco'];
// if we not pass at first time index use the first column for the index or what you want
if(!$sidx) $sidx =1; 


// connect to the MySQL database server 
$db = mysql_connect(DBHOST,DBUSER,DBPASSWD) or die("Connection Error: " . mysql_error()); 

// select the database 
 mysql_select_db(DBNAME) or die("Error connecting to db."); 

// calculate the number of rows for the query. We need this for paging the result 


$result = mysql_query("SELECT COUNT(*) AS count FROM gestionacompte where   idAgence=$idagenceco ORDER BY IdAcompte"); 
$row = mysql_fetch_array($result,MYSQL_ASSOC) or die(mysql_error()); 
$count = $row['count']; 


// calculate the total pages for the query 
 if( $count > 0) { 
          $total_pages = ceil($count/$limit); 
} else { 
            $total_pages = 0; 
} 

// if for some reasons the requested page is greater than the total 
// set the requested page to total page 
if ($page > $total_pages) $page=$total_pages;

// calculate the starting position of the rows 
 $start = $limit*$page - $limit;

// if for some reasons start position is negative set it to 0 
// typical case is that the user type 0 for the requested page 
 if($start <0) $start = 0; 

// the actual query for the grid data 
$SQL = "SELECT IdAcompte, numAgence, nomAcompte, prenomAcompte, numSemaine, societe, montantAcompte, typeReglement, dateAcompte, idAgence FROM gestionacompte where idAgence=$idagenceco ORDER BY $sidx"; 
$result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error()); 


// we should set the appropriate header information. Do not forget this.
header("Content-type: text/xml;charset=utf-8");

$s = "<?xml version='1.0' encoding='utf-8'?>";
$s .=  "<rows>";
$s .= "<page>".$page."</page>";
$s .= "<total>".$total_pages."</total>";
$s .= "<records>".$count."</records>";


// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$s .= "<row id='". $row['IdAcompte']."'>";  
$s .= "<cell>". $row['IdAcompte']."</cell>";
$s .= "<cell>". $row['numSemaine']."</cell>";
$s .= "<cell>". $row['numAgence']."</cell>";
$s .= "<cell>". $row['nomAcompte']."</cell>";
$s .= "<cell>". $row['prenomAcompte']."</cell>";
$s .= "<cell>". $row['societe']."</cell>";
$s .= "<cell>". $row['montantAcompte']."</cell>";
$s .= "<cell>". $row['typeReglement']."</cell>";
$s .= "<cell>". $row['dateAcompte']."</cell>";
$s .= "<cell>". $row['idAgence']."</cell>";
$s .= "</row>";
}
$s .= "</rows>"; 

echo $s;

?>

1 个答案:

答案 0 :(得分:0)

我很确定这是由&gt;&gt;

引起的
onSelectRow: function(id){
    if(id && id!==lastsel2){
        $('#list').jqGrid('restoreRow',lastsel2);
        $('#list').jqGrid('editRow',id,true,'','','','',reload);
        lastsel2=id;

            }
}

并通过inlineEditing it-self。

我建议你使用cellEditing。