0

I've looked at several posts but don't understand how to use jsonReader. I would like to keep my primary key hidden when editing, adding. If I make my permissionID editable:false or hidden it wont edit.

Any help or direction to other posts would be great and very appreciated. thanks

Here is my code:

$(document).ready(function()
    {   
        $("#list").jqGrid(
        {
            url:'Users2.cfc?method=getUsers', //CFC that will return the users
            datatype: 'json', //We specify that the datatype we will be using will be JSON
            colNames:['Bill To Code','User ID', 'GL_comp_key', 'Branch ID', 'Warehouse ID', 'Final Approver',  'Active', 'Primary Approver', 'Administrative','Secondary Approver','permissionID'], //Column Names
            //The Column Model to define the data. Note you can make columns non sortable, specify width, alignment, etc.
            colModel :[
                {name:'ar_bill_key',index:'ar_bill_key', width:125, sorttype:"text",editable:true,searchoptions:{sopt:['eq','lt','le','gt','ge','bw','ew','cn']},
                    editable:true,edittype:"text",editoptions:{size:50},editrules:{required:true},formoptions:{elmprefix:"(*)"}},
                {name:'userID',index:'userID', width:125, align:"left",sorttype:"text",searchoptions:{sopt:['eq','bw','ew','cn']},
                    editable:true,edittype:"text",editoptions:{size:50},editrules:{required:true},formoptions:{elmprefix:"(*)"}},
                {name:'gl_cmp_key',index:'gl_cmp_key', width:125, align:"left",sorttype:"text",searchoptions:{sopt:['eq','bw','ew','cn']},
                    editable:true,edittype:"text",editoptions:{size:50},editrules:{required:true},formoptions:{elmprefix:"(*)"}},
                {name:'so_brnch_key',index:'so_brnch_key', width:125, align:"left",sorttype:"text",searchoptions:{sopt:['eq','bw','ew','cn']},
                    editable:true,edittype:"text",editoptions:{size:50},editrules:{required:true},formoptions:{elmprefix:"(*)"}},
                {name:'so_whs_key',index:'so_whs_key', width:125,align:"left",sorttype:"text",searchoptions:{sopt:['eq','bw','ew','cn']},
                    editable:true,edittype:"text",editoptions:{size:50},editrules:{required:true},formoptions:{elmprefix:"(*)"}},
                {name:'final_approver',index:'final_approver', width:125,align:"left",sorttype:"text",searchoptions:{sopt:['eq','bw','ew','cn']},
                    editable:true,edittype:"select",editoptions:{value:"1:Yes;0:No"},editrules:{required:true},formoptions:{elmprefix:"(*)"}},  
                {name:'active',index:'active', width:125,align:"left",sorttype:"text",searchoptions:{sopt:['eq','bw','ew','cn']},
                    editable:true,edittype:"select",editoptions:{value:"1:Yes;0:No"},editrules:{required:true},formoptions:{elmprefix:"(*)"}},
                {name:'primary_approver',index:'primary_approver', width:125,align:"left",sorttype:"text",searchoptions:{sopt:['eq','bw','ew','cn']},
                    editable:true,edittype:"select",editoptions:{value:"1:Yes;0:No"},editrules:{required:true},formoptions:{elmprefix:"(*)"}},  
                {name:'admin',index:'admin', width:125,align:"left",sorttype:"text",searchoptions:{sopt:['eq','bw','ew','cn']},
                    editable:true,edittype:"select",editoptions:{value:"1:Yes;0:No"},editrules:{required:true},formoptions:{elmprefix:"(*)"}},  
                {name:'secondary_approver',index:'secondary_approver', width:130,align:"left",sorttype:"text",searchoptions:{sopt:['eq','bw','ew','cn']},
                    editable:true,edittype:"select",editoptions:{value:"1:Yes;0:No"},editrules:{required:true},formoptions:{elmprefix:"(*)"}},
                {name:'permissionID',index:'permissionID',sorttype:"int",editable:true,searchoptions:{sopt:['eq','lt','le','gt','ge']}},
            ],//searchoptions parameter is used to limit the operators available during search
            pager: $('#pager'), //The div we have specified, tells jqGrid where to put the pager
            rowNum:20, //Number of records we want to show per page
            rowList:[20,30,40,50], //Row List, to allow user to select how many rows they want to see per page
            sortorder: "desc", //Default sort order
            sortname: "ar_bill_key", //Default sort column
            viewrecords: true, //Shows the nice message on the pager
            imgpath: '/images', //Image path for prev/next etc images
            caption: 'Permissions', //Grid Name
            recordtext: "Record {0} - {1} of {2}",//Pager information to show
            rownumbers: true,//Show row numbers
            rownumWidth: "30",//Width of the row numbers column
            sortable: true,
            height:'auto', //I like auto, so there is no blank space between. Using a fixed height can mean either a scrollbar or a blank space before the pager
            mtype:'POST',   
            toolbar:[true,"top"], //Shows the toolbar at the top. We will use it to display user feedback
            //The JSON reader. This defines what the JSON data returned from the CFC should look like
            jsonReader: {
                root: "ROWS", //our data
                page: "PAGE", //current page
                total: "TOTAL", //total pages
                records:"RECORDS", //total records
                userdata:"USERDATA", //Userdata we will pass back for feedback
                cell: "", //Not Used
                ar_bill_key: "0" //Will default to first column
                },
            editurl:"Users2.cfc?method=addeditUser" //The Add/Edit function call                
            }               
        ).navGrid('#pager',
            {
                search:true,searchtitle:"Search",//title set for hover over display
                edit:true,edittitle:"Edit User",
                add:true,addtitle:"Add User",
                del:false,deltitle:"Delete User"
            },
        // Edit Options. savekey parameter will keybind the Enter key to submit.
        {editCaption:"Edit User",edittext:"Edit",closeOnEscape:true, savekey: [true,13],errorTextFormat:commonError
            ,reloadAfterSubmit:true,bottominfo:"Fields marked with (*) are required",top:"60",left:"70",width:500}, 
        {width:500,addCaption:"Add User",edittext:"Add",closeOnEscape:true,savekey: [true,13],errorTextFormat:commonError,
            reloadAfterSubmit:true,bottominfo:"Fields marked with (*) are required",top:"60",left:"70"}, //Add Options
        {url:"Users2.cfc?method=delUser",caption:"Delete User",closeOnEscape:true,errorTextFormat:commonError,top:"60",left:"70",
            reloadAfterSubmit:true}, //Delete Options
         //Search Options. multipleSearch parameter lets it know we are going to use the new advanced search feature
        {errorTextFormat:commonError,Find:"Search",closeOnEscape:true,caption:"Search Users",multipleSearch:true,closeAfterSearch:true}
        );          

        //Function will be called when add/edit encounters an error. The returned message is what will be shown to user 
        function commonError(data)
        {           
            return "Error Occured during Operation. Please try again";
        }

    }
);
Oleg
  • 219,533
  • 32
  • 395
  • 775
Sue
  • 61
  • 1
  • 1
  • 12
  • Oleg, thanks for your response. I want to have the permissionid hidden at all times. I found a way that seems to work. What do you think of this? {name:'permissionID',index:'permissionID',sorttype:"int",hidden:true,editable:true,resizable:false,editrules:{readonly:true}}, Also how do I display the message usaer added in a div on the grid header? Thanks very much!! Your posts are great!! – Sue Feb 27 '12 at 20:53

1 Answers1

1

If I understand correct your question you want just that permissionID will be send during editing, but you not need to display it somewhere.

I suppose, that your original problem that you don't specify which id should has the rows of the grid. The JSON input should contain the id. If you use cell: "" setting in the jsonReader you have to specify the id of the row in one from the two ways:

  • you included key: true property in the definition of the column 'permissionID'. In the case you don't need to mark the column editable (you can remove editable:true).
  • if you never need to display to the user the column 'permissionID' you can remove column 'permissionID' and just include in the jsonReader the property id: "10". If I calculated correct you placed the primary key permissionID as the 10-th position. In the case the value of permissionID will be saved only as the id of the rows (<tr> elements) of the grid. The id will be always send in all edit operations.
Oleg
  • 219,533
  • 32
  • 395
  • 775
  • I'm having trouble getting the edit to work if I don't pass the primary key permissionID in because I have WHERE permissionID = #Val(Arguments.permissionID)# in my update query. – Sue Feb 27 '12 at 21:04
  • Hurray!! I used your suggestion of ID ="10" I finally figured out what that meant and arranged my query to match it. Thanks very very much When I am allowed to give you votes I will do it!! – Sue Feb 27 '12 at 21:10
  • @Sue: You are welcome! I am glad that I could help you. If the problem is solved you can ["accept"](http://meta.stackexchange.com/a/5235/147495) the answer. Every accepted answer gives you some reputation points. After you will have 15 reputation points you receive the right to vote up 30 questions or answers per day. Best wishes to you! – Oleg Feb 27 '12 at 21:31
  • @Sue: One more advice: you should remove `imgpath` option which is deprecated (see [here](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:upgrade_from_3.4.x_to_3.5#options)). You can consider to use `formatter: "checkbox", edittype: "checkbox"` which can reduce the total width of the grid. You can remove all default properties (like `align:"left",sorttype:"text"`). I recommend you also to use column templates (see [here](http://stackoverflow.com/a/6047856/315935)). It can reduce the size of the JavaScript code and improve it readability and manageability. – Oleg Feb 27 '12 at 21:41
  • Hi Oleg,I have posted a question: http://stackoverflow.com/questions/9506231/jqgrid-dependent-selects-for-edit-form-with-coldfusion-cfc – Sue Mar 05 '12 at 20:40
  • @Sue: I have no examples where one uses `dataUrl` together with dependent selects, but it should be implemented in the same way like [here](http://stackoverflow.com/a/4480184/315935). – Oleg Mar 05 '12 at 20:48
  • Hi Oleg,I have posted a question: http://stackoverflow.com/questions/9506231/jqgrid-dependent-selects-for-edit-form-with-coldfusion-cfc I am trying to use dataUrl to set up 3 selects, 1st select a value and the next 2 can be selected based on a query to the database using the first ID. I have tried to set up build select and a change function from the documents but I canot get ny data to display. The data is there in firebug like this:{"COLUMNS":["SO_WHS_KEY"],"DATA":[["WC01"],["WC02"],["WCAC"], I know something is wrong with columns vs rows can you suggest where is the docs on this. Thanks – Sue Mar 05 '12 at 20:51
  • Thank you for the response. I am trying to use your example. – Sue Mar 05 '12 at 20:55
  • @Sue: I read your question before, but it's written too unclear. You wrote about 3 selects, but included in the code only one. You included a lot of absolutely unneeded information like `commonSubmit` function which you never use, many column and so on. I don't understand which relevance has how you fill the grid (JSON data) with the way how you edit it. I can only you recommend carefully read and debug the demo from [my old answer](http://stackoverflow.com/a/4480184/315935). I think it should help you to solve your main problem with dependent selects. – Oleg Mar 05 '12 at 21:04
  • Thanks very much, I am going through your example line by line now and setting it up with my data. I really need more training and knowledge before doing this but it's for work so I have to find a way. – Sue Mar 05 '12 at 21:25