0

I am using jQuery 1.5.1, jQuery UI 1.8.13 and jqGrid 4.2.0.

Here is what I am trying to do:

I am trying to apply jqGrid to several tables (all have same structure) using tabletoGrid. Each table has the same class, but also has unique autogenerated id. I also have a div with a unique id after each table.

Corresponding to each table, there is a link, which when clicked would bring up the edit row popup for that table.

The tables all get jqGrid applied fine. No problem there. But the navigation pager does not show up in the pager div and neither do the form edit input controls inside the popup edit box. The edit form popup comes up, but it only has the previous, next, submit and cancel buttons, but no input boxes for the fields.

Am I missing some include files? I do not see any javascript errors. Any help is greatly appreciated. Thanks.

-- jqr

<link rel="stylesheet" href="/js/jquery1.8.13/css/custom-theme/jquery-ui-1.8.13.custom.css" />

<link rel="stylesheet" href="/js/jqgrid4.2.0/css/ui.jqgrid.css" />
<link rel="stylesheet" href="/js/jqgrid4.2.0/plugins/ui.multiselect.css" />



<script type="text/javascript" src="/js/jquery1.8.13/js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="/js/jquery1.8.13/js/jquery-ui-1.8.13.custom.min.js"></script>

<script type="text/javascript" src="/js/jqGrid4.2.0/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="/js/jqGrid4.2.0/plugins/ui.multiselect.js"></script>
<script type="text/javascript" src="/js/jqGrid4.2.0/src/grid.tbltogrid.js" ></script>
<script type="text/javascript" src="/js/jqGrid4.2.0/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="/js/jqGrid4.2.0/src/grid.formedit.js"></script>

<script type="text/javascript">
$(document).ready(function() {
var editOpt = {
                    editData:{
                        myparam:function(){
                            return "myval";
                        }
                    },
                    height:240,
                    reloadAfterSubmit: true,
                    editCaption:'Edit Recordxxx',
                    bSubmit:'Save',
                    url:'someurl.php',
                    closeAfterEdit:true,
                    viewPagerButtons:false
                };

var oGridOptions = 
{
  "colNames":[
    "Field1",
    "ReField1",
    "Head",
    "Line Item",
    "Modified By",
    "Date"
  ],
  "colModel":[
    {
      "name":"Field1",
      "index":"Field1",
      "width":65,
      "title":true,
      "hidden":false,
      "widthOrg":65,
      "resizable":true,
      "sortable":true,
      "edittype":"text",
      "editable":"true",
      "editoptions":{
        "size":"10"
      }
    },
    {
      "name":"ReField1",
      "index":"ReField1",
      "width":71,
      "title":true,
      "hidden":false,
      "widthOrg":75,
      "resizable":true,
      "sortable":true,
      "edittype":"text",
      "editable":"true",
      "editoptions":{
        "size":"10"
      }
    },
    {
      "name":"Head",
      "index":"Head",
      "width":48,
      "title":true,
      "hidden":false,
      "widthOrg":50,
      "resizable":true,
      "sortable":true,
      "edittype":"text",
      "editable":"true",
      "editoptions":{
        "size":"10"
      }
    },
    {
      "name":"Line_Item",
      "index":"Line_Item",
      "width":600,
      "title":true,
      "hidden":false,
      "widthOrg":631,
      "resizable":true,
      "sortable":true,
      "edittype":"text",
      "editable":"true",
      "editoptions":{
        "size":"10"
      }, 
      "classes": "LineItemText"
    },
    {
      "name":"Modified_By",
      "index":"Modified_By",
      "width":190,
      "title":true,
      "hidden":false,
      "widthOrg":200,
      "resizable":true,
      "sortable":true,
      "edittype":"text",
      "editable":"true",
      "editoptions":{
        "size":"10"
      }
    },
    {
      "name":"Date",
      "index":"Date",
      "width":96,
      "title":true,
      "hidden":false,
      "widthOrg":100,
      "resizable":true,
      "sortable":true,
      "edittype":"text",
      "editable":"true",
      "editoptions":{
        "size":"10"
      }
    }
  ]
};

$.jgrid.edit.editCaption = "My Edit Caption";
$.jgrid.defaults.rownumbers = true;
$.jgrid.defaults.pgtext = "Page {0} of {1}";


tableToGrid("table.DataTablex", oGridOptions); 
jQuery("table.DataTablex").each(function(i) {
    var idx = i + 1;
    var sid = "#table" + idx.toString();
    var snavId = "#pagernav" + idx.toString();
    jQuery(sid).jqGrid('setGridParam',{"pager":snavId});
    jQuery(sid).jqGrid('navGrid',snavId,{edit: true, add: true, del: true}, editOpt);



$(".bedata").click(function(){ 
    var iwhich = this.id;
    var sTableId = "#table" + iwhich.toString();
    var gr = jQuery(sTableId).jqGrid('getGridParam','selrow'); 
    if( gr != null )  {
        jQuery(sTableId).jqGrid('editGridRow',gr,{height:280,reloadAfterSubmit:false}); 
    }
    else 
        alert("Please Select Row"); 
      }); 

});
</script>
jquerybug
  • 145
  • 1
  • 10

1 Answers1

1

I suppose that your main problem is the usage of "editable":"true" instead of "editable":true or just editable:true. You should additionally remove widthOrg attribute from colModel which will be used for internal purpose.

One more problem. If you include jquery.jqGrid.min.js you should not include grid.tbltogrid.js and grid.formedit.js. If you opens jquery.jqGrid.min.js you will see in the comment at the beginning of the file after the text * Modules: the list of all jqGrid modules included. Including of the same modules one more time can follow to serious problems.

By the way if you define objects you don't need to place all property names in quotes. So all names on the left from ':' in the object initialization ("colNames", "colModel", "name", "index", ...) can be written without "" characters. Many attributes which you use (for example, "title":true, "hidden":false, "resizable":true, "sortable":true, "edittype":"text", ...) have default values. You can remove there to make the code shorter and better readable. In the documentation you will find default values for all colModel properties and all jqGrid options.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks, removed the quotes around "true", now the edit form comes up good, but still no navigation pager with buttons. Regarding the unnecessary options, I first called tabletogrid with no options, had the internally generated options object print to the console (with JSON.stingify), ran JSON beautifier on the string and used that string as the options object. Any idea why the navigation pager does not show up? Thanks again. – jquerybug Oct 13 '11 at 22:17
  • @jquerybug: The `pager` parameter of `jqGrid` must be define in the `oGridOptions` and can't be changed later with `setGridParam` (see the value in the "Can be changed?" column of [documentation] (http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options)). So you should define `oGridOptions`. You should create the corresponding divs `"#pagernavX"` before. You can alternatively consider to use `toppager:true` parameter (see [here](http://stackoverflow.com/questions/4402455/unable-to-position-pager-navigation-bar-above-jqgrid/4402903#4402903)). – Oleg Oct 13 '11 at 22:49
  • thanks. I did away with the extra div for navigation and just used toppager. I sincerely appreciate your answers, they helped me greatly. I learned a lot from your answers to other questions here and from your samples. You should write a book about jqgrid. It is much needed. – jquerybug Oct 15 '11 at 19:21
  • @jquerybug: You are welcome! I am glad to read that my other answers was helpful for you. I had the idea to write the book and it I'll find the time for it I will do this. – Oleg Oct 15 '11 at 19:28
  • your example files are very helpful to me. I really wish there is an index of all your jqgrid demos somewhere. Do you already have an index somewhere? Thank you very much. -jqr – jquerybug Oct 17 '11 at 15:18
  • @jquerybug: Currently there are no index, but I plan the do this in the next time. Thanks, for advice. – Oleg Oct 17 '11 at 15:28