0

Main grid code is below

$(document).ready(function () {
    jQuery("#list5").jqGrid({
        url: 'server.php?mode=getBaseList',
        datatype: "json",
        colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Notes'],
        colModel: [{
            name: 'id',
            index: 'id',
            width: 55
        }, {
            name: 'invdate',
            index: 'invdate',
            width: 90
        }, {
            name: 'name',
            index: 'name',
            width: 100
        }, {
            name: 'amount',
            index: 'amount',
            width: 80,
            align: "right"
        }, {
            name: 'tax',
            index: 'tax',
            width: 80,
            align: "right"
        }, {
            name: 'total',
            index: 'total',
            width: 80,
            align: "right"
        }, {
            name: 'note',
            index: 'note',
            width: 150,
            sortable: false
        }],
        rowNum: 10,
        jsonReader{
         id:'id',repeatitems:false
        },
        rowList: [10, 20, 30],
        pager: '#pager5',
        sortname: 'name',
        autoencode: true,
        loadonce:true,
        sortable: true,
        viewrecords: true,
        sortorder: "desc",
        multiselect: false,
        subGrid: true,
        subGridRowExpanded: function(subgrid_id, row_id) { 
        var newID = $('#list5').getCell(row_id, 'id');
        var escapeID=escape(newID);

        var subgrid_table_id, pager_id; 
        subgrid_table_id = subgrid_id+"_t"; 
        pager_id = "p_"+subgrid_table_id; 
        $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>"); 
        jQuery("#"+subgrid_table_id).jqGrid({ 
        url:"/portal/getSubGridData?id="+escapeID, 
        datatype: "json", 
        colNames: ['No','Item','Qty','Unit','Line Total'], 
        colModel: [ 
        {name:"num",index:"num",width:80,key:true}, 
        {name:"item",index:"item",width:130}
        ], 
        rowNum:20, 
        pager: pager_id, 
        sortname: 'num', 
        sortorder: "asc", 
        height: '100%' 
        }); 
        jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false}) }
        caption: "Simple data manipulation"
    }).navGrid("#pager5", {
        edit: false,
        add: false,
        del: false
    });
});
jQuery("#list5").jqGrid('filterToolbar',{searchOperators : true});

How to pass URI having parameter values with space? I observe that '%20' or '_' is cancelled out in the JS. What should I do?

I tried : Step 1 : using id

id=10054898 104143018

var modifiedUrl=escape(id);

New url as below

my url is below

newUrl=/portal/getSubGridData?id=10054898%20104143018

Step 2: using name

name=John Williams

var modifiedUrl=escape(name);

New url as below

my url is

newUrl=/portal/getSubGridData?name=John%20Williams

Above url not post to server side, i have checked the firebug. The url not getting submitted.

  • What is the error you get when attempting to make the POST request? – Rory McCrossan Dec 03 '14 at 12:02
  • Where is JavaScript code which you use? If you use `postData` the problem should not exist at all. One can use `encodeURIComponent` or to use `$.param` method of jQuery. If you poste **JavaScript** code which you use I could post you my answers with the corresponding example. – Oleg Dec 03 '14 at 12:04
  • I have use post method(mtype is post). but server side is not getting fed with data – Krishnakumar Subbaiyan Dec 03 '14 at 12:05
  • Why you need append parameters to **URL** and not to the body if you use `mtype: "POST"`? How you get the parameter information in your server code? Do you ignore all standard parameters which send you jqGrid? By the way, do you really use ids like `"10054898 104143018"` in the main grid or you use `"10054898_104143018"`? – Oleg Dec 03 '14 at 12:07
  • I want to send to server side the below URL: /portal/getSubGridData?id=10054898 0104143018. (ie parameter with space). EncodeURL/escape are not working.please guide me to send the data with space in url – Krishnakumar Subbaiyan Dec 03 '14 at 12:11
  • If i am remove the below code for main grid. jsonReader{id:'id',repeatitems:false}. url post working but i want jsonReader for getting id functions – Krishnakumar Subbaiyan Dec 03 '14 at 12:21
  • You should stop to **describe** the code which you use. You should **post code fragments** of the code which you use instead. Posting `jsonReader` have no sense if you don't post an example of input data which you use. It should contains at least 1-2 rows of data. – Oleg Dec 03 '14 at 12:30
  • Oleg i have updated my question with full code please check... – Krishnakumar Subbaiyan Dec 03 '14 at 12:46
  • Do you read my answer? You don't posted and test data like I asked you. The value of `row_id` should be the same as `var newID = $('#list5').getCell(row_id, 'id');`. You don't use `mtype: "POST"` in the code above. So the usage of `url:"/portal/getSubGridData", postData: {id: row_id}` seems me the most easy way. If you ever need to encode URL you should use `encodeURIComponent` instead of `escape`. Independent from the described implementation the usage of spaces in `id` is incorrect in HTML. – Oleg Dec 03 '14 at 13:09
  • See [here](http://www.w3.org/TR/html5/dom.html#the-id-attribute) for example: "The value must not contain any space characters." – Oleg Dec 03 '14 at 13:12
  • I had replaced space to underscore but still its not work, i have tried mtype: 'post'. now url is /portal/getSubGridData?id=10054898_104143018. – Krishnakumar Subbaiyan Dec 03 '14 at 13:41
  • What is "not work" exactly? Do you verified that the URL was used? Which data were send in the body of HTTP POST request? You can use Developer Tools of Google Chrome, Internet Explorer or Firefox to see all HTTP traffic. – Oleg Dec 03 '14 at 14:38
  • Hi Oleg, Thanks for spending time for me. I have fixed the issue. Space containing url is supported by jqGrid and working fine. But, the issue is i have added the json reader id as my parameter id. So the grid is taking table tr id with same space for id So not able to load as the div html tag skips the url post. Now i have changed the id containing no space and its works! – Krishnakumar Subbaiyan Dec 04 '14 at 06:06

1 Answers1

0

I suppose that you use Subgrid as Grid and you create subgrid with the code like

subGridRowExpanded: function(subgridId, rowId) {
    var id = $.jgrid.stripPref(this.p.idPrefix, rowId);
    ...
    $subgrid.jqGrid({
        url: "/portal/getSubGridData?id=" + id,
    });
    ...
}

You should never add common string value as part of URL. Instead of that you should use either the standard JavaScript method encodeURIComponent

        url: "/portal/getSubGridData?id=" + encodeURIComponent(id),

or jQuery.param method

        url: "/portal/getSubGridData?" + $.param({id: id}),

Even more easy would be to use

        url: "/portal/getSubGridData",
        postData: {
            id: id
        }

In the case the id will be added to other parameter which will be sent to the server and which I hope you get and analyse on the server side. If you use HTTP GET then you access the parameter using $_GET in PHP. If you use mtype: "POST" then you access the parameter using $_POST (someting like $_POST["id"]). I'm not PHP developer, but I don't see why one could append some parameters to URL and to post another parameter using the standard way: inside of the body of HTTP POST request.

The last remark: I strictly recommend you don't use spaces in the id. Depend on which version of HTML you use it could be prohibited. I'd recommend you better to use underscore instead of space.

Oleg
  • 220,925
  • 34
  • 403
  • 798