- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Trirand.com 的 jqgrid,但无法通过内置表单对话框添加或编辑数据。当我编辑和/或添加数据并点击提交时,数据会刷新,但没有任何变化。我检查了 PHPmyadmin,没有数据被更改或添加到数据库中。
如有任何帮助,我们将不胜感激。
编辑
HTML/Jquery 代码
jQuery(document).ready(function(){
jQuery("#grid").jqGrid("initFontAwesome").jqGrid({
pager:'#pager',
url:'getunits.php',
datatype: "json",
mtype: 'GET',
height: 300,
width: 1000,
colNames:['Unit Id', 'Div Id', 'Title Org', 'Short Desc', 'Long Desc', 'Comments', 'Enabled'],
colModel:[
{name:'unit_id',
index:'unit_id',
width:40,
editable:true,
sortable:false,
resizable:false,
align:"center",
editoptions:{size:7,maxlength:6},
editrules:{required:true,number:true},
formoptions:{elmprefix:"(*)"}
},
{name:'div_id',
index:'div_id',
width:30,
editable:true,
sortable:false,
resizable:false,
align:"center",
editoptions:{size:4,maxlength:4},
editrules:{required:true,number:true},
formoptions:{elmprefix:"(*)"}
},
{name:'title_org',
index:'title_org',
width:60,
editable:true,
sortable:false,
resizable:false,
editoptions:{size:11,maxlength:11},
editrules:{required:true,number:true},
formoptions:{elmprefix:"(*)"}
},
{name:'short_desc',
index:'short_desc',
width:50,
editable:true,
resizable:false,
sortable:false,
editoptions:{size:7,maxlength:10},
editrules:{required:true},
formoptions:{elmprefix:"(*)"}
},
{name:'long_desc',
index:'long_desc',
width:230,
editable:true,
resizable:false,
sortable:false,
edittype:"textarea",
editoptions:{rows:"2",cols:"30",maxlength:60},
editrules:{required:true},
formoptions:{elmprefix:"(*)"}
},
{name:'unit_desc',
index:'unit_desc',
width:230,
editable:true,
resizable:false,
sortable:false,
edittype:"textarea",
editoptions:{rows:"2",cols:"30",maxlength:60}
},
{name:'avail_ind',
index:'avail_ind',
width:40,
editable:true,
resizable:false,
sortable:false,
align:"center",
edittype:"select",
editoptions:{value:"Y:Y;N:N"}
}
],
pager: jQuery('#gridpager'),
viewrecords: true,
sortorder: "asc",
sortname: "div_id",
caption:"Unit Codes",
editurl:'getunits.php',
toppager:true,
recordtext:'',
hidegrid:false,
scroll:true,
rowNum:"10000"
});
jQuery("#grid").jqGrid('navGrid','#grid_toppager',
{
add:true,
edit:true,
view:true,
search:false,
del:false,
refresh:false
},
{ // Edit form
width:"auto",
height:"auto",
top:220,
left:500,
viewPagerButtons:false,
topinfo:"Fields marked with (*) are required",
resize:false
},
{ // Add form
width:"auto",
height:"auto",
top:220,
left:500,
topinfo:"Fields marked with (*) are required",
resize:false,
reloadAfterSubmit:true,
closeAfterAdd: true
},
{ // prmDel
},
{ //prmSearch
},
{ //prmView
top:220,
left:460
}
);
}); // jQuery("#grid").jqGrid
</script>
PHP 代码
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "*******";
$dbname = "fdmamaint";
$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$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, $dbpass) or die("Connection Error: " . mysql_error());
mysql_select_db($dbname) or die("Error conecting to db.");
$result = mysql_query('SELECT unit_id, div_id, title_org, short_desc, long_desc, unit_desc, avail_ind FROM depunits where avail_ind="Y" and active_ind="Y"');
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 )
{
$total_pages = cell($count/$limit);
}
else
{
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
$SQL = 'SELECT unit_id, div_id, title_org, short_desc, long_desc, unit_desc, avail_ind FROM depunits where avail_ind="Y" and active_ind="Y"';
$result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error());
$response->page = $page;
$response->total = $total_pages;
$response->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$response->rows[$i]['id']=$row[unit_id];
$response->rows[$i]['cell']=array($row[unit_id],$row[div_id],$row[title_org],$row[short_desc],$row[long_desc],$row[unit_desc],$row[avail_ind]);
$i++;
}
echo json_encode($response);
?>
已更新
EditDivisions.php
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "*****";
$dbname = "fdmamaint";
// connect to the database
$mysql_connect($dbhost, $dbuser, $dbpass) or die("Connection Error: " . mysql_error());
mysql_select_db($dbname) or die("Error conecting to db.");
$div = mysql_real_escape_string($_GET['div_id']);
$l2 = mysql_real_escape_string($_GET['l2_id']);
$l1l2 = mysql_real_escape_string($_GET['l1l2_id']);
$l1l3 = mysql_real_escape_string($_GET['l1l3_id']);
$l2l3 = mysql_real_escape_string($_GET['l2l3_id']);
$beg = mysql_real_escape_string($_GET['exec_beg']);
$end = mysql_real_escape_string($_GET['exec_end']);
$csa = mysql_real_escape_string($_GET['csa_id']);
$area = mysql_real_escape_string($_GET['area_id']);
$areadesc = mysql_real_escape_string($_GET['area_desc']);
$shortdesc = mysql_real_escape_string($_GET['short_desc']);
$longdesc = mysql_real_escape_string($_GET['long_desc']);
$enabled = mysql_real_escape_string($_GET['avail_ind']);
if($_GET['oper']=='add'){
mysql_query("INSERT INTO depdivisions (div_id, l1l2_id, l2_id, l1l3_id, l2l3_id, exec_beg, exec_end, csa_id, area_id, area_desc, short_desc, long_desc, avail_ind) values ($div,$l1l2,$l2,$l1l3,$l2l3,$beg,$end,$csa,$area,$areadesc,$shortdesc,$longdesc,$enabled");
}else if($_GET['oper']=='edit'){
}else if($_GET['oper']=='del'){
}
?>
最佳答案
回答 JCooper 评论(我的印象是网格基本代码中有内置函数来处理它们。它不是在 jquery.jqGrid.src.js 内部吗?
).
它是如何工作的:
在您编辑的 php 页面/文件(getunits.php
,不确定这是一个好的选择,因为它与您的“load_data”URL 相同)中,您必须检查用户是否添加、编辑或删除:
// Here, we use $_GET, because you ask for it in configuration.
$unit_id = $_GET['unit_id']; // And so on for the other form values
if($_GET['oper']=='add'){
// mysql insert
}else if($_GET['oper']=='edit'){
// mysql update
}else if($_GET['oper']=='del'){
// mysql delete
}
操作完成后,将使用“load_data”URL 再次加载网格。
关于javascript - Jqgrid无法添加或编辑数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20226055/
我的 jqgrid 中有一个状态栏。 如果状态为事件,我希望同一行中的另一个单元格为绿色。如果状态为“未激活”,我希望单元格为红色。 如何做到这一点? 截至目前,我已经在“图像”行上创建了一个自定义格
我正在使用 jqgrid 显示服务器中存在的数据如何在鼠标悬停工具提示上显示数据描述。 这是在 jqgrid 上显示工具提示的最佳方式? 最佳答案 鼠标悬停时 jqGrid 中显示的工具提示只不过是相
我有一个 asp.net 项目,它使用 jqgrid 作为 javascript 网格。如何找出正在使用的 jqgrid 版本? 最佳答案 如果您需要以编程方式查询版本,您可以使用: $.jgrid.
有没有办法以编程方式(在 Javascript 中,而不是服务器端)过滤当前显示在 jqGrid 中的数据?所有搜索示例似乎都依赖于使用 jqGrid 自己的搜索 UI,这对我不起作用。例如,我希望能
有没有一种方法可以切换网格的multiselect选项? 如果在创建网格时multiselect不是multiselect,则更改网格的TRUE参数并要求重新加载具有禁用或不创建标题列时将标题留在后面
我在jqGrid中使用列重新排序功能 $grid = jQuery("#list").jqGrid({ sortable:true, ... }); 重新排列列后是否会触发事件?如果有
我正在构建我的第一个ASP.NET MVC 3应用程序并使用jqGrid。我的其中一个列“Flavor Created”是日期列,我想使用DatePicker过滤该列上的网格。当前发生的情况是:用户单
我试图基于选定的行启用导航。因此,用户从jQgrid中选择一行,然后按show(有一个显示网格的按钮,我看到了edit,add等),它需要根据url转到新页面(该行的一部分) )。 $(documen
有没有办法设置 jqgrid 列的固定宽度(最大和最小)? 我已经在 colmodel 中设置了宽度属性,但是如果我调整网格的大小,列正在调整。 最佳答案 不能定义列的最大和最小宽度,但可以使其具有固
我被困在这里-生产前要做的最后一件事。 来自oracle的日期采用以下格式:“ 8/14/2012 10:46:48 AM” 我在jqgrid上使用以下内容: { name: 'CreationDat
我是 jqGrid 的新手,谁能解释一下 jqgrid colModel 中 Index 属性的用途 最佳答案 如果您使用datatype: "json" 或datatype: "xml" 没有额外使
我正在学习 jqGrid,希望最终能将它连接到 Redis 数据库。作为第一步,我正在处理本地数据。这是我必须使用可排序行(在网格中拖放行)。网格出现并且看起来不错,列甚至可以排序,但我无法选择一行并
我想每 5 分钟重新加载一次 jqgrid(给定间隔时间),是否有任何选项/事件。如何做到这一点? 最佳答案 您可以使用setInterval JavaScript函数进行自动刷新 var grid
我正在学习 jqGrid,希望最终能将它连接到 Redis 数据库。作为第一步,我正在处理本地数据。这是我必须使用可排序行(在网格中拖放行)。网格出现并且看起来不错,列甚至可以排序,但我无法选择一行并
大家好,我正在使用 JQ Grid,我得到的日期格式是 2012-09-16T00:00:00,就像这样。我希望日期格式采用 2012-09-16 方式。我试图改变它,但它不起作用。请查看我的代码并告
当我搜索 JQGrid 使用的图标时,我找到了包含所有图标的单个 PNG 文件。我想知道它如何使用图像的一部分作为 JQGrid 中使用的按钮的图标。 最佳答案 jqGrid 使用来自 jQuery
我使用 loadonce 预先获取所有数据,然后在本地进行排序和过滤。 我的列值之一是一个对象数组。在 colModel 选项中,我使用了如下所示的格式化程序函数: function my_forma
我想要在 jqGrid 中右键单击列标题时的列名称。任何代码将不胜感激。 最佳答案 可以绑定(bind)contextmenu事件到所有列标题。每个标题都是 元素等它的 DOM 支持 cellInde
我想计算总计 无需在 calctotal.php 中执行即可即时完成。从本质上讲,这是一个计算列。我想使用一些事件,如 afterInsertRow ,但即使没有事件,它也会将列数据移动一格,因为 X
我有一些数据想在 jqqgrid 中显示。除了添加、编辑和删除之外,还可以对选定记录执行其他操作。我喜欢在该记录的行中有一个用于该操作的按钮/链接的流程。有没有办法在 jqgrid 中添加未绑定(bi
我是一名优秀的程序员,十分优秀!