Home › Forums › Guriddo jqGrid JS › Help › dataUrl (editoptions for select) is not working in JQGRID
Tagged: ajax, dataSelect, dataUrl, editoptions, inlinenav, jqgrid
Hi,
I’m using JQGRID and code as below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
$("#jqGridDel").jqGrid({ url: "Data.aspx/BindInfo", datatype: 'json', mtype: 'POST', serializeGridData: function (postData) { return JSON.stringify(postData); }, ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }, colName: ['DelId', 'Name', 'DeliveryName', 'Status'], colModel: [ { label: 'Del No', name: 'DelId', width: 35 }, { label: 'Gate', name: 'Name', width: 200, editable: true, edittype: "select", foramtter: "Select", editoptions: { dataUrl: "Data.aspx/BindDDInfo" } }, { label: 'Delivery', name: 'DeliveryName', width: 150, editable: true }, { label: 'Active', name: 'Status', width: 40, editable: true, align: "center", formatter: "checkbox", edittype: "checkbox", editoptions: { value: '1:0' } } ], loadonce: true, width: 1050, height: "100%", pager: "#jqGridDelPager", caption: "Configuration", rowNum: 15, jsonReader: { page: function (obj) { return 1; }, total: function (obj) { return 1; }, records: function (obj) { return obj.d.length; }, root: function (obj) { return obj.d; }, repeatitems: false, id: "QGDelId" }, onSelectRow: function (id) { if (id && id !== lastSelQGDel) { lastSelQGDel = id; } }, ajaxRowOptions: { contentType: 'application/json; charset=utf-8' }, serializeRowData: function (postData) { return JSON.stringify({ editQGData: postData }); }, editurl: "Data.aspx/SaveData" }); $('#jqGridDel').navGrid("#jqGridDelPager", { edit: false, add: false, del: false, refresh: false, search: false, view: false }); $('#jqGridDel').inlineNav('#jqGridDelPager', // the buttons to appear on the toolbar of the grid { edit: true, add: true, del: true, refresh: true, cancel: true, editParams: { keys: true, rowid: lastSelQGDel, restoreAfterError: true, reloadAfterSubmit: true, successfunc: function (result) { if (result.responseJSON.d == "Success") alert("Data saved successfully!!"); else alert("There is some error in data processing"); setTimeout(function () { $("#jqGridDel").jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid'); }, 50); } }, addParams: { keys: true, addRowParams: { successfunc: function (result) { if (result.responseJSON.d == "Success") alert("Data saved successfully!!"); else alert("There is some error in data processing"); setTimeout(function () { $("#jqGridDel").jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid'); }, 50); } } } |
Using below reference files..
<script src=”Scripts/jquery-1.11.0.min.js” type=”text/javascript”></script>
<script src=”Scripts/grid.locale-en.js” type=”text/javascript”></script>
<script src=”Scripts/jquery.jqGrid.min.js” type=”text/javascript”></script>
<script src=”Scripts/jquery-ui.min.js” type=”text/javascript”></script>
I’m able to load the data and save the same from JQGRID to SQL Database and vice versa.
but, select option (column: Gate) is not loading any data.. i tried to debug the code and understood that the dataUrl is not firing during editing row via inline-nav.
the code behind function BindDDInfo returns string in <Select> <Option>……</Option> </Select> format.
Can any one help me out to get the data into dropdown in JQGRID.
Kind Regards,
NM1988
Hello,
We have tested your code and it seems to work as expected.
The main reason that you do not load data is that the expression:
dataUrl: “Data.aspx/BindDDInfo”
is not valid url. You can very easy see this in debug console using Chrome or FireBug or newer IE.
Kind Regards,
Will
Guriddo Support Team
Thanks Team for your response.
checked through F12 (in IE9), could see Response Header as below
<span class=”typ”>Response</span><span class=”pln”> HTTP</span><span class=”pun”>/</span><span class=”lit”>1.1</span> <span class=”lit”>200</span><span class=”pln”> OK
</span><span class=”typ”>Server</span><span class=”pln”> ASP</span><span class=”pun”>.</span><span class=”pln”>NET </span><span class=”typ”>Development</span> <span class=”typ”>Server</span><span class=”pun”>/</span><span class=”lit”>10.0</span><span class=”pun”>.</span><span class=”lit”>0.0</span>
<span class=”typ”>Date</span> <span class=”typ”>Wed</span><span class=”pun”>,</span> <span class=”lit”>24</span> <span class=”typ”>Feb</span> <span class=”lit”>2016</span> <span class=”lit”>15</span><span class=”pun”>:</span><span class=”lit”>07</span><span class=”pun”>:</span><span class=”lit”>16</span><span class=”pln”> GMT
X</span><span class=”pun”>-</span><span class=”typ”>AspNet</span><span class=”pun”>-</span><span class=”typ”>Version</span> <span class=”lit”>4.0</span><span class=”pun”>.</span><span class=”lit”>30319</span>
<span class=”typ”>Cache</span><span class=”pun”>-</span><span class=”typ”>Control</span> <span class=”kwd”>no</span><span class=”pun”>-</span><span class=”pln”>cache</span><span class=”pun”>,</span> <span class=”kwd”>no</span><span class=”pun”>-</span><span class=”pln”>store
</span><span class=”typ”>Pragma</span> <span class=”kwd”>no</span><span class=”pun”>-</span><span class=”pln”>cache
</span><span class=”typ”>Expires</span> <span class=”pun”>-</span><span class=”lit”>1</span>
<span class=”typ”>Content</span><span class=”pun”>-</span><span class=”typ”>Type</span><span class=”pln”> text</span><span class=”pun”>/</span><span class=”pln”>html</span><span class=”pun”>;</span><span class=”pln”> charset</span><span class=”pun”>=</span><span class=”pln”>utf</span><span class=”pun”>-</span><span class=”lit”>8</span>
<span class=”typ”>Content</span><span class=”pun”>-</span><span class=”typ”>Length</span> <span class=”lit”>69186</span>
<span class=”typ”>Connection</span> <span class=”typ”>Close</span>
Response body returning data.aspx html page and not sure what went wrong.
I’ve added ajaxSelectOptions: { cache: false, type: ‘POST’ } — still not working.
Note: I’ve placed debug point in BindDDInfo function and it’s not getting hit from dataUrl but debug point got hit when i’ve mentioned same function in url (to pick data to jqgrid).
So, not sure what went wrong. Could you please have a look on this.
Hello,
To be a clear BinDDInfo is a function or url?
If the dataUrl is function it should return URL string and not data.
In ajaxSelectOptions add error function like this
1 2 3 4 5 6 7 8 9 |
...jqGrid({ ... ajaxSelectOptions : { error : function(xhr, status, error) { alert(error); }, ... } ... |
Regards,
Will
Guriddo Support Team
BindDDInfo is webmethod in codebehind (in Data.aspx). I’ll try the mentioned one and will let you know the status.
Kind regards,
NM1988
Hi Team,
I’ve tried the option (error) but nothing resulted. I’ve <span class=”comment-copy”> found something interesting…. i gave ‘Data.aspx/Bind’ for dataUrl where there is no webmethod ‘Bind’ exists in codebehind (in Data.aspx.cs) but still ResponseHeader stating HTTP/1.1 200 OK and understood that Responsebody filled with Data.aspx (even with BindDDInfo). So, any issues with Jqgrid version?</span>
Hello,
First which version is used?
Which jQuery version is used?
There is nothing special we just use standard jQuery ajax.
the code behind this is something like this:
1 2 3 4 5 6 7 8 |
$.ajax($.extend({ url: $.isFunction(options.dataUrl) ? options.dataUrl.call($t, rowid, vl, String(options.name)) : options.dataUrl, type : "GET", dataType: "html", data: $.isFunction(postData) ? postData.call($t, rowid, vl, String(options.name)) : postData, context: {elem:elem, options:options, vl:vl}, success: function(data){ .... |
You can test what is returned from this if yo do not use jqGrid.
Make simple ajax call like this and see the response
Kind Regards,
Will
Guriddo Support Team
Hi Team,
I’ve found the issue, that is due to HttpHandler and corrected the same. Now, i’ve changed my webmethod to return ‘List<Dictionary<string, object>>’ and the below code
ajaxSelectOptions: { type: ‘POST’,
contentType: ‘application/json; charset=utf-8’,
datatype: ‘json’,
success: function (result) {
alert(JSON.stringify(result));
}
}
Alert is showing as below
{“d”:[{“ID”:1,”Name”:”Test1″},{“ID”:2,”Name”:”Test2″}]}
but, buildSelect is not getting hit ,
dataUrl: “Data.aspx/BindDDInfo”,
buildSelect: function (response) {
var data = typeof response === “string” ? JSON.stringify(response) : response,
s = “<select>”;
s += ‘<option value=”0″>–Select–</option>’;
$.each(data, function () {
s += ‘<option value=”‘ + this.ID + ‘”>’ + this.Name + ‘</option>’;
});
return s + “</select>”;
}
Could you please have an idea on this.
Hello,
If you do console.log(response) in buildSelect what you see?
just alert the response in buildSelect and see what is?
Regards
Guriddo Support Team
Hi Team,
I’ve tried the console.log(response) and alert(response) in buildSelect but it doesn’t give any popup.
Kind Regards,
NM1988
Hello,
The reason not to run buildSelect are mainly two
Be a sure that both are meet.
You do not answer our question – which version of jqGrid and jquery are used?
Kind Regards,
Will
Guriddo Support Team
Hi Team,
Apologies for delay!!
I’m usnig Guriddo_jqGrid_JS_5.0.2
Kind Regards, NM1988
Hello,
We have a demo which work file. You can look at this example
I think that is something wrong with your server response and how the data is send to the client.
Kind Regards,
Will
Guriddo Support Team
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top