簡體   English   中英

jqgrid-添加,編輯,刪除不起作用

[英]jqgrid - add,edit,delete isn't working

我無法添加,編輯,刪除,搜索

甚至我把editrules:{required:true}也行不通。

(firebug中的錯誤顯示“ isEmtpy不起作用”)


這是我的代碼...

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jqgrid</title> 

    <!-- installation files of jqgrid -->
    <link rel="stylesheet" type="text/css" media="screen" href="themes/redmond/jquery-ui-1.8.16.custom.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="themes/ui.jqgrid.css" />
    <script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
    <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
    <!-- installation files of jqgrid -->

<script type="text/javascript"> 

function mypricecheck(value, colname) {
if (value < 0 || value >20) 
   return [false,"Please enter value between 0 and 20"];
else 
   return [true,""];
}

    jQuery().ready(function (){

        jQuery("#list1").jqGrid({
            url:'server.php?q=1',
            datatype: 'xml',
            //colNames:['ProductCode','ProductCategoryID', 'ProductBrandID', 'ProductDescription','ProductOriginal','ProductCompatible','ProductDealerPrice'],
            colModel:[
                {name: "ProductCode", index: "ProductCode", label: "รหัสสินค้า", width: 50, editable:true, key: true  , edittype: 'text', editoptions: { dataInit: function (el) { $(el).css('text-transform', 'uppercase'); }} },
                {name: "ProductCategoryID", index: "ProductCategoryID", label: "หมวดหมู่", width: 60, editable: true, edittype: 'select', editoptions:{value:{Toner:'Toner',Inkjet:'Inkjet',Ribbon:'Ribbon','Fax Film':'Fax Film'}} },
                {name: "ProductBrandID", index: "ProductBrandID", label: "แบรนด์", width: 50, editable: true, edittype: 'select', editoptions:{dataUrl: "optbrand.php"} },
                {name: "ProductDescription", index: "ProductDescription", label: "คำอธิบาย", width: 120, editable: true},
                {name: "ProductOriginal", index: "ProductOriginal", label: "รุ่นออริจินัล", width: 140, editable: true},
                {name: "ProductCompatible", index: "ProductCompatible", label: "เหมาะสำหรับรุ่น", width: 200, editable: true},
                {name: "ProductDealerPrice", index: "ProductDealerPrice", label: "ราคาเดลเลอร์", width: 40, editable: true, editrules:{number:true},sorttype:'number',formatter:'number'}
            ],
            rowNum:10,
            autowidth: true,
            rowList:[10,20,30],
            pager: jQuery('#pager1'),
            sortname: 'ProductCategoryID',
            viewrecords: true,
            sortorder: "asc",
            caption: 'ฐานข้อมูลสินค้า',
            rownumbers:true, 
            height:'auto',
            editurl:'server.php',
        });

        jQuery("#list1").jqGrid('navGrid','#pager1',{edit:true,add:true,del:true,view:true,search:true,refresh:true});
    });
</script>

</head>
<body>
<table id="list1"></table>
<div id="pager1"></div>
</body>
</html>

server.php

<?php
include "jq-config.php";
$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
if($limit < 0) $limit = 10;
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
if(!$sidx) $sidx =1;
// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());

mysql_select_db($database) or die("Error conecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM tb_product");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];

if( $count >0 ) {
    $total_pages = ceil($count/$limit);
} else {
    $total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if($start <0)
{
    $start = 0;
}
$SQL = "SELECT * FROM tb_product ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldnt execute query.".mysql_error());

if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
header("Content-type: application/xhtml+xml;charset=utf-8"); } else {
header("Content-type: text/xml;charset=utf-8");
}
$et = ">";

echo "<?xml version='1.0' encoding='utf-8'?$et\n";
echo "<rows>";
echo "<page>".$page."</page>";
echo "<total>".$total_pages."</total>";
echo "<records>".$count."</records>";
// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    echo "<row id='". $row[ProductCode]."'>";
    echo "<cell>". $row[ProductCode]."</cell>";

    $tmp = $row['ProductCategoryID'];
    $sql1 = "SELECT ProductCategoryName FROM tb_productcategory WHERE ProductCategoryID = '$tmp' ";
    $result1 = mysql_query($sql1) or die (mysql_error());
    list($ProductCategoryName) = mysql_fetch_row($result1);
    $tmp = $row['ProductBrandID'];
    $sql1 = "SELECT ProductBrandName FROM tb_productbrand WHERE ProductBrandID = '$tmp' ";
    $result1 = mysql_query($sql1) or die (mysql_error());
    list($ProductBrandName) = mysql_fetch_row($result1);

    echo "<cell><![CDATA[". $ProductCategoryName."]]></cell>";
    echo "<cell><![CDATA[". $ProductBrandName."]]></cell>";
    //echo "<cell>". $row[ProductCategoryID]."</cell>";
    //echo "<cell>". $row[ProductBrandID]."</cell>";
    echo "<cell><![CDATA[". $row[ProductDescription]."]]></cell>";
    echo "<cell><![CDATA[". $row[ProductOriginal]."]]></cell>";
    echo "<cell><![CDATA[". $row[ProductCompatible]."]]></cell>";
    echo "<cell>". $row[ProductDealerPrice]."</cell>";
    echo "</row>";
}
echo "</rows>";     

?>

請幫助,

謝謝,

周一

這是jqGrid 4.3.2版本的第二個版本中的已知錯誤。 您可以在答案此處閱讀詳細信息。 現在,該問題已在github上的jqGrid代碼中解決。 因此,您可以從此處下載jquery.jqGrid.src.js的固定版本,也可以從github下載jqGrid的最新版本。 在最后一種情況下,您必須遵循說明如何使用jqGrid模塊而不是一個jquery.jqGrid.src.jsjquery.jqGrid.min.js文件的說明。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM