0

我有一些问题,我想使用 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 的值,因为我在我的萤火虫中看到,idms 无法识别(null)所以 sql 函数正在下降。

4

3 回答 3

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})
                                                                                              });

});
于 2013-07-01T10:29:54.340 回答
0
$(".deletethisrecord").live('click',function(e){ e.preventDefault(); 
toDelete = $(this).parent().parent().attr('id');
    $("#list2").jqGrid(
        'delGridRow',
        toDelete,
          { url: '<?php echo $edit; ?>', 
            reloadAfterSubmit:false}
    );
});

});

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

于 2013-07-01T08:16:36.447 回答
0

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

此外,我建议您从网格中删除不存在的属性add:true, del:true以及值colModelindex属性值相同的属性,从网格name中删除默认值并将其添加到网格中。您还可以删除选项(删除最后一个参数),因为所有值都是默认值(请参阅文档)。repeatitems: truejsonReadergridview: trueautoencode: true{edit:true,add:true,del:true}navGrid

于 2013-07-01T08:29:54.473 回答