EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Punkerr on October 26, 2012, 09:27:25 AM



Title: Delete, Update, Save: edatagrid problem
Post by: Punkerr on October 26, 2012, 09:27:25 AM
Hi, i have this problem:

DEFINITION edatagrid jscript:
Code:
		$(function() {
$('#dg').edatagrid({
url: 'get.php',
saveUrl: 'save.php',
updateUrl: 'update.php',
destroyUrl: 'destroy.php?ID='+row.ARTICLE, <!-- not working :(
rowStyler: function(index, row) {
if (row.QTY > row.STOCK) {
return 'color:red;font-weight:bold;';
}
}

});
});
HTML:
Code:
	<table id="dg" title="Planner" style="width:1200px;height:530px"
toolbar="#toolbar" pagination="true" idField="ID" url="get.php"  
iconCls="icon-save" rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="ARTICLE" width="30">Article</th>
<th field="DESCRIPTION" width="110">Description</th>
<th field="CLIENT" width="30">Client</th>
<th field="CATEGORY" width="30">Category</th>
<th field="A102" width="15" editor="{type:'numberbox',options:{required:true}}" align="right">A102</th>
<th field="A104" width="15" editor="{type:'numberbox',options:{required:true}}" align="right">A104</th>
<th field="A105" width="15" editor="{type:'numberbox',options:{required:true}}" align="right">A105</th>
<th field="A109" width="15" editor="{type:'numberbox',options:{required:true}}" align="right">A106</th>
<th field="A110" width="15" editor="{type:'numberbox',options:{required:true}}" align="right">A110</th>
<th field="A111" width="15" editor="{type:'numberbox',options:{required:true}}" align="right">A111</th>
<th field="A116" width="15" editor="{type:'numberbox',options:{required:true}}" align="right">A116</th>
<th field="QTY" width="15" align="right">Total</th>
<th field="STOCK" width="15" align="right">Stock</th>
<th field="DIF" width="15" align="right" formatter="qtyNegative">Diferences</th>
</tr>
</thead>
</table>
<div id="toolbar" style="padding:5px;height:auto">
     <div align="center">
            <span>Article Code:</span>
            <input id="articleid">
            <span>Article:</span>
            <input id="article">
            <span>Client:</span>
            <input id="clientid">
            <span>Category:</span>
            <input id="category">
            <a href="#" class="easyui-linkbutton" iconCls="icon-ok" plain="true" onClick="doSearch()">Do Filter</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-no" plain="true" onClick="clearSearch()">Clear Filter</a>
        </div>
        <div style="margin-bottom:5px" align="right">  
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onClick="javascript:$('#dg').edatagrid('destroyRow')">Delete Row</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onClick="javascript:$('#dg').edatagrid('saveRow')">Save Row Changes</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onClick="javascript:$('#dg').edatagrid('cancelRow')">Cancel Edition</a>
        </div>
</div>

DELETE SERVER CODE:
Code:
<?php

$id 
$_REQUEST['ID'];

include 
'conn.php';

$sql "DELETE PUTBLPLANNER WHERE ARTICLE=$id";
@
mysql_query($sql);
echo 
json_encode(array('success'=>true));
?>

I traced the query and ID comes in blank: "DELETE PUTBLPLANEADOR WHERE ARTICLE="

I'm doing something wrong?

By the way, I traced save and update, and nothing happens. Get Rows and Search (only textboxes not combos and lists) works fine to me.

Please, if someone checks the code, really appreciate it.


Title: Re: Delete, Update, Save: edatagrid problem
Post by: stworthy on October 26, 2012, 01:02:45 PM
What is the id field? Is it ARTICLE or ID? If the ARTICLE is the id field, please correct the idField property as:

idField="ARTICLE"


Title: Re: Delete, Update, Save: edatagrid problem
Post by: Punkerr on October 26, 2012, 01:29:56 PM
Ok I'm set it like you suggested, and redefined some things... but still the same problem:

TABLE:
IDARTICLEARTDESCRIPTIONCLIENTCATEGORYA102QTYSTOCKDIFERENCES
52BVL1833120NBVLGARI FRAGBVLGARIFRAGANCES55105
53BVL1833124NBVLGARI FRAGBVLGARIFRAGANCES44106
54BVL1833420NBVLGARI FRAGBVLGARIFRAGANCES33107

JSCRIPT:
Code:
		$(function() {
$('#dg').edatagrid({
url: 'get.php',
saveUrl: 'save.php',
updateUrl: 'update.php',
destroyUrl: 'destroy.php',
rowStyler: function(index, row) {
if (row.QTY > row.STOCK) {
return 'color:red;font-weight:bold;';
}
}

});
});

HTML:
Code:
	<table id="dg" title="Planner" style="width:1200px;height:530px"
toolbar="#toolbar" pagination="true" idField="ID" url="get.php"  
iconCls="icon-save" rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="ARTICLE" width="30">Article</th>
<th field="ARTDESCRIPTION" width="110">Description</th>
<th field="CLIENT" width="30">Client</th>
<th field="CATEGORY" width="30">Category</th>
<th field="A102" width="15" editor="{type:'numberbox',options:{required:true}}" align="right">A102</th>
<th field="QTY" width="15" align="right">Total</th>
<th field="STOCK" width="15" align="right">Stock</th>
<th field="DIFERENCES" width="15" align="right" formatter="qtyNegative">Diferences</th>
</tr>
</thead>
</table>
<div id="toolbar" style="padding:5px;height:auto">
     <div align="center">
            <span>Article Code:</span>
            <input id="articleid">
            <span>Article:</span>
            <input id="article">
            <span>Client:</span>
            <input id="clientid">
            <span>Category:</span>
            <input id="category">
            <a href="#" class="easyui-linkbutton" iconCls="icon-ok" plain="true" onClick="doSearch()">Do Filter</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-no" plain="true" onClick="clearSearch()">Clear Filter</a>
        </div>
        <div style="margin-bottom:5px" align="right">  
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onClick="javascript:$('#dg').edatagrid('destroyRow')">Delete Row</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onClick="javascript:$('#dg').edatagrid('saveRow')">Save Row Changes</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onClick="javascript:$('#dg').edatagrid('cancelRow')">Cancel Edition</a>
        </div>
</div>

SERVER CODE (destroy.php):
Code:
<?php
include 'conn.php';
$id $_REQUEST['ID'];
$sql "DELETE PUTBLPLANEADOR WHERE ID=$id";
@
mysql_query($sql);
echo 
json_encode(array('success'=>true));
?>

And I worry about update, doesn't work  :-\ :
SERVER CODE (update.php):
Code:
<?php
include 'conn.php';
$id $_REQUEST['ID'];
$a102 intval($_REQUEST['A102']);

$sql "UPDATE PUTBLPLANEADOR SET A102=$a102, QTY=$a102 WHERE ID=$id";
@
mysql_query($sql);
echo 
json_encode(array(
'ARTICLE' => $id,
'A102' => $a102

));
?>

Get and Search works fine, any idea?, thanks in advance!


Title: Re: Delete, Update, Save: edatagrid problem
Post by: stworthy on October 26, 2012, 06:42:51 PM
The json returned from update.php should include the id field.
Code:
echo json_encode(array(
‘ID’ => ...,
‘ARTICLE' => ...,
'A102' => ...
));


Title: Re: Delete, Update, Save: edatagrid problem
Post by: Punkerr on October 26, 2012, 07:41:17 PM
Thank you I will try.

And any idea about the problem with destroy rows?


Title: Re: Delete, Update, Save: edatagrid problem
Post by: Punkerr on October 27, 2012, 04:24:07 PM
Oh god it works! thanks stworthy, update works so cool.
For delete, I changed all query to lower case, and finally it works!