0

I have some problem, I want to delete some row using JqGrid plugin

Here's my php delete function, the database colum for id is 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();
}

and my jqgrid setting

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

How to get value of idms_department, because I see in my firebug, the idms is not recognizing (null) so the sql function is falling.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
randytan
  • 1,029
  • 5
  • 23
  • 52

3 Answers3

1

I am pasting example code for you please refer it, may be it will be help you.

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

});
Nisarg
  • 3,024
  • 5
  • 32
  • 54
0
$(".deletethisrecord").live('click',function(e){ e.preventDefault(); 
toDelete = $(this).parent().parent().attr('id');
    $("#list2").jqGrid(
        'delGridRow',
        toDelete,
          { url: '<?php echo $edit; ?>', 
            reloadAfterSubmit:false}
    );
});

});

use some thing like this. place delete in your record list.

Gaurav Mehra
  • 471
  • 7
  • 20
0

The documentation of delGridRow describes what will be sent to the server on Delete operation. The name of rowid is id instead of idms_department which you use in your code (see the line $deptid = $_REQUEST['idms_department'];). You should either use the name 'id' in the statement or add prmNames: {id: "idms_department"} option to jqGrid. It changes the default name of id used in Add/Edit/Delete operation.

Additionally I would recommend you remove non existing properties add:true, del:true from colModel and index properties which value are the same as values of name properties, remove default value repeatitems: true from jsonReader and add gridview: true and autoencode: true to the grid. You can additionally remove {edit:true,add:true,del:true} option (remove the last parameter) of navGrid because all the values are default (see the documentation).

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • hi oleg thanks for your answer, but now when i'm change the value, the database value is changed but the jqgrid reloads and nothing shows up. It also the same if i create new value, the insert function is executed, the data stored in db but, when reloads, jqgrid is shows up nothing. can you help me? – randytan Jul 01 '13 at 13:28
  • @randytan: It sounds very strange. jqGrid reload the grid per default (if you not use `reloadAfterSubmit: false` explicitly). It means that you should have **full new data**. Even if you would use wrong caching HTTP headers then you would see *old data*, but not nothing. I recommend you to use [Fiddler](http://fiddler2.com/get-fiddler), [Firebug](http://getfirebug.com/) or Developer Tools of IE/Chrome to trace full HTTP traffic between the server and jqGrid. You will see whether the server provide wrong data. – Oleg Jul 01 '13 at 13:43
  • hi oleg, yes, i have see the firebug response. THere are two responses which is right. 1. GET the data and shows in Grid 2. EDIT the data and send POST data to server 3. GET again the new data and shows in Grid but in the step three, the grid is not write the data, although the server send the right data. is there any possibilities? – randytan Jul 01 '13 at 13:51
  • hi @oleg, what i have done so far, i create the master page which contain departments (this thread) jqgrid, that page is working perfectly. Then i copy exact page and exact php script then editing some database value so it match with the column name. But in this page, the jqgrid acts strange. I can send you the screenshot step by step action that i take with Firebug Responses. – randytan Jul 01 '13 at 14:05
  • @randytan: You should just *debug* the JavaScript code inclusive jqGrid source code. You can set breakpoints [here](https://github.com/tonytomov/jqGrid/blob/v4.5.2/js/grid.base.js#L1954) and [here](https://github.com/tonytomov/jqGrid/blob/v4.5.2/js/grid.base.js#L1971) and follow the processing of the response. You should use `jquery.jqGrid.src.js` instead of `jquery.jqGrid.min.js` of cause. – Oleg Jul 01 '13 at 14:37
  • i just created new thread here: http://stackoverflow.com/questions/17407283/jqgrid-act-strange-reloading-data-after-insert-and-update – randytan Jul 01 '13 at 14:47
  • @randytan: If there are a bug in jqGrid then one have to *debug* the code like I described. Do you see some data if you just reload the page which has 11 rows (by clicking on "Reload" button in navigator bar of the grid or reload the page in web browser)? Do you have the page online and can provide URL where one can see the problem (please use `jquery.jqGrid.src.js` instead of `jquery.jqGrid.min.js` in the demo)? – Oleg Jul 01 '13 at 16:13
  • @randytan: I tried the URL which you posted (the departments.php part) and it worked without any problem on IE10. The only suspected thing in my opinion is that the response of the server from `/kbase/itinv/functions/get_dept.php` have **wrong HTTP header Content-Type**. It contains `Content-Type: text/html` instead of `Content-Type: application/json`. – Oleg Jul 02 '13 at 08:25
  • thanks for your test, but this not working in other links than departments. jqgrid in The departments page is working, but in location and module page it's broken. shall we continue this discussion in chat? – randytan Jul 02 '13 at 08:27
  • I recommend you additionally to update jQuery which you use from version 4.4.4 to the current version 4.5.2. – Oleg Jul 02 '13 at 08:27
  • i have just updated to 4.5.2 version. but still not working in my local machine and the server version. – randytan Jul 02 '13 at 08:35
  • I debugged the Location demo and I think that I fond the reason of the problem. I'll post shortly my answer with details. – Oleg Jul 02 '13 at 08:38