简体   繁体   中英

jqgrid - add,edit,delete isn't working

I can't add,edit,delete,search

and even i put editrules:{required:true} also doesn't work.

(error in firebug shown that "isEmtpy is not function")


this is mycode...

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>";     

?>

help please,

thanks,

mon

It's known bug in the second version of jqGrid 4.3.2 version. You can read details in the answer and here . The problem is now fixed in the code of jqGrid on the github. So you can either download the fixed version of the jquery.jqGrid.src.js from here or download the last version of jqGrid from github . In the last case you have to follow the instructions which describes how to use jqGrid modules instead of one jquery.jqGrid.src.js or jquery.jqGrid.min.js file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM