【问题标题】:JqGrid Delete FunctionJqG​​rid删除函数
【发布时间】:2013-07-01 07:55:21
【问题描述】:

我有一些问题,我想使用 JqGrid 插件删除一些行

这是我的 php 删除函数,id 的数据库列是 idms_department

if($oper == 'del'){
   $deptid = $_REQUEST['idms_department'];
   $del = "DELETE FROM ms_department WHERE idms_department =" . $deptid;
   if(mysql_query($del)){
     "Delete Successfull"; 
   } else {
     die("Error Delete: " .mysql_error()."SQL : " .$del);
   }
     mysql_close();
}

还有我的 jqgrid 设置

  <script type="text/javascript">
        $(document).ready(function() {
            //alert("start");
            jQuery("#departments").jqGrid({
                mtype:'GET',
                url:'functions/get_dept.php',
                editurl:'functions/edit_dept.php',
                datatype: "JSON",
                colNames:['Department ID','Department'],
                colModel:[
                    {name:'idms_department',index:'idms_department', width:150, editable:true,add:true, del:true, key:true},
                    {name:'department',index:'department', width:800,editable:true, add:true, del:true}     
                ],
                loadComplete: function () {
                alert("OK");
                },    
                loadError: function (jqXHR, textStatus, errorThrown) {
                    alert('HTTP status code: ' + jqXHR.status + '\n' +
                          'textStatus: ' + textStatus + '\n' +
                          'errorThrown: ' + errorThrown);
                    alert('HTTP message body (jqXHR.responseText): ' + '\n' + jqXHR.responseText);
                },
                rowNum:10,
                rowList:[5,10,15],
                pager: '#pager-departments',
                sortname: 'idms_department',
                viewrecords: true,
                jsonReader: {repeatitems: true, idms_department: "idms_department" },
                sortorder: "asc",
                caption:"Example Departments"
            });
            jQuery("#departments").jqGrid('navGrid','#pager-departments',{edit:true,add:true,del:true});
            jQuery("#departments").jqGrid('gridResize',{minWidth:350,maxWidth:850,minHeight:80, maxHeight:350});
            //alert("end");
        });
    </script>

如何获取 idms_department 的值,因为我在我的 firebug 中看到,idms 无法识别(null)所以 sql 函数正在下降。

【问题讨论】:

    标签: php mysql json jqgrid sql-delete


    【解决方案1】:

    我正在为您粘贴示例代码,请参考它,可能会对您有所帮助。

        jQuery("#list_requisitos").jqGrid(
                        {
                            url:'../ajax/common_form_detail.php?form_id='+form_id,
                            editurl:'../ajax/common_form_edit.php?form_id='+form_id,
                            datatype: "json",
                            colNames:['D','ID','AREA','PIN Transportador','Fecha creacion','Aprob. Gestor Operativo','Aprob. Gestor Administrativo','Usuario que registra','Contratista','Fecha EjecucionDe la Tarea','Periodo','Anexos'],
                            colModel:[{name:'boton_grupos_tematicos',index:'boton_grupos_tematicos',sortable:false, align:'center',width:'50',search:false},{name:'id',index:'id',editable:false,hidden:true},{name:'object_area',
                                index:'object_area',
                                formoptions:{elmsuffix:''},    
                                editable:true,
                                editrules:{required:true},
                                hidden:false,
                                search:true,
                                edittype:'select',
                                formatter:'select', 
                               editoptions: {value: ''}
                                },{name:'pin_transportador',
                                index:'pin_transportador',
                                formoptions:{elmsuffix:''},editrules:{required:true},editable:true,
                                hidden:false,
                                search:true,
                                editoptions: {size:80, maxlength: 1000}
                                },{name:"created_date",
                                index:"created_date",
                                formoptions:{elmsuffix:"(aaaa-mm-dd)"},
                                sorttype:"date", editoptions:{dataInit: function(element) {$(element).datepicker({dateFormat: "yy-mm-dd"})}},
                                search:true,
                                type:"text",
                                searchoptions:
                    {
                                    dataInit: seleccionarFecha,
                                    attr: {title: "Selecciona una fecha"}
                    }
                                },{name:'app_by_codinator',
                                index:'app_by_codinator',
                                editable:true,
                                search:true,
                                edittype:'select',
                                formatter:'select', 
                                editoptions: {value: '0:NO;1:SI;-1:RECHAZADO'}},{name:'app_by_manager',
                                index:'app_by_manager',
                                editable:true,
                                search:true,
                                edittype:'select',
                                formatter:'select', 
                                editoptions: {value: '0:NO;1:SI;-1:RECHAZADO'}},{name:"user_id",index:"user_id",type:"text",editable:false,hidden:false},{name:"contractor_id",index:"contractor_id",type:"text",editable:false,hidden:true},{name:"actual_task_done_date",index:"actual_task_done_date",type:"text",editable:false,hidden:false,editoptions:{dataInit: function(element) {$(element).datepicker({dateFormat: "yy-mm-dd"})}},},{name:"sumerized_date",index:"sumerized_date",type:"text",editable:false,hidden:false},{name:"attachments",index:"attachments",type:"text",editable:false,hidden:false}],
                            rowNum:20,
                            rowList:[20,50,100],
                            pager: '#pager_requisitos',
                            sortname: 'id',
                            viewrecords: true,
                            multiselect: true,
                            sortorder: "asc",
                            autowidth: true,
                            height: 400,
                            width: 900,
                            caption:"RG05 IN340_pin_transportador",
                        });
                        jQuery("#list_requisitos").jqGrid('navGrid','#pager_requisitos',{ edit:true,add:true,del:true,search:false},{width:780,recreateForm:true},{width:780,recreateForm:true})
                        .jqGrid('filterToolbar',{stringResult: false,searchOnEnter : false, autosearch: true})
                                                                                                  });
    
    });
    

    【讨论】:

      【解决方案2】:

      The documentation of delGridRow 描述了删除操作时将发送到服务器的内容。 rowid 的名称是id,而不是您在代码中使用的idms_department(参见$deptid = $_REQUEST['idms_department']; 行)。您应该在语句中使用名称'id' 或将prmNames: {id: "idms_department"} 选项添加到jqGrid。它更改了添加/编辑/删除操作中使用的默认名称id

      另外,我建议您从colModelindex 属性中删除不存在的属性add:true, del:true,这些属性的值与name 属性的值相同,从jsonReader 中删除默认值repeatitems: true 并添加@ 987654340@ 和 autoencode: true 到电网。您还可以删除navGrid{edit:true,add:true,del:true} 选项(删除最后一个参数),因为所有值都是默认值(请参阅the documentation)。

      【讨论】:

      • 您好,感谢您的回答,但是现在当我更改值时,数据库值已更改,但 jqgrid 重新加载并且没有任何显示。如果我创建新值,执行插入函数,数据存储在 db 中,但重新加载时,jqgrid 什么也没有显示,这也是一样的。你能帮帮我吗?
      • @randytan:听起来很奇怪。 jqGrid 默认重新加载网格(如果您没有明确使用reloadAfterSubmit: false)。这意味着您应该拥有完整的新数据。即使您使用错误的缓存 HTTP 标头,您也会看到 旧数据,但不是什么也没有。我建议您使用FiddlerFirebug 或 IE/Chrome 的开发者工具来跟踪服务器和 jqGrid 之间的完整 HTTP 流量。你会看到服务器是否提供了错误的数据。
      • 嗨,奥列格,是的,我看到了萤火虫的反应。有两个回答是正确的。 1. 获取数据并在网格中显示 2. 编辑数据并将 POST 数据发送到服务器 3. 再次获取新数据并在网格中显示但是在第三步中,网格没有写入数据,尽管服务器发送正确的数据。有没有可能?
      • 嗨@oleg,到目前为止我所做的,我创建了包含部门(此线程)jqgrid 的母版页,该页面运行良好。然后我复制准确的页面和准确的 php 脚本,然后编辑一些数据库值,使其与列名匹配。但是在这个页面中,jqgrid 的行为很奇怪。我可以向您发送我使用 Firebug 响应采取的逐步操作的屏幕截图。
      • @randytan:您应该只调试包含 jqGrid 源代码的 JavaScript 代码。您可以设置断点herehere 并跟踪响应的处理。您应该使用 jquery.jqGrid.src.js 而不是 jquery.jqGrid.min.js 的原因。
      【解决方案3】:
      $(".deletethisrecord").live('click',function(e){ e.preventDefault(); 
      toDelete = $(this).parent().parent().attr('id');
          $("#list2").jqGrid(
              'delGridRow',
              toDelete,
                { url: '<?php echo $edit; ?>', 
                  reloadAfterSubmit:false}
          );
      });
      
      });
      

      使用类似的东西。将删除放在您的记录列表中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-02
        • 2011-07-04
        • 1970-01-01
        • 2011-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多