jqgrid - 添加,编辑,删除不起作用 [英] jqgrid - add,edit,delete isn't working

查看:76
本文介绍了jqgrid - 添加,编辑,删除不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法添加,编辑,删除,搜索

I can't add,edit,delete,search

甚至我放置了editrules:{required:true}也不起作用。

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

(萤火虫中的错误显示isEmtpy不是函数)

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

这是我的代码......

this is mycode...

index.html

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

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

?>

求助,

谢谢,

mon

推荐答案

第二版jqGrid 4.3中已知错误.2版本​​。您可以在答案这里。现在问题已解决在github上的jqGrid代码中。所以你可以从 jquery.jqGrid.src.js jqGrid / jquery.jqGrid-4.3.2_ / js / jquery.jqGrid.src-this.jsrel =nofollow>这里或从 github 。在最后一种情况下,您必须遵循说明描述了如何使用jqGrid模块而不是一个 jquery.jqGrid.src.js jquery.jqGrid.min.js 文件。

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.

这篇关于jqgrid - 添加,编辑,删除不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆