Forum


09:51

05/05/2011

{"groupOp":"AND","rules":[
{"field":"source","op":"eq","data":"searchvalue1"},
{"field":"est","op":"eq","data":"searcvvalue2"}
]}
public ActionResult GetData(string sidx, string sord, int page, int rows, string filters)
12:30

10/08/2009

If you would use Entity Framework to access to the database the code will be relatively easy. Look at the "UPDATED" part of the answer to download the ASP.NET MVC 2.0 Project. The example demonstrate filtering, paging and sorting.
Best regards
Oleg
15:32

05/05/2011

Thank you. Great sample.
Erorr handler used in this code fails if inline editing is used, eq. if bad data is entered so some row, exception is sent to jqGrid in json format.
jqGrid shows *raw json error data* in default error window in this case, defined parser/error hander is not executed.
Most important issue: User corrects error and press Enter again to save. In this case data is *not saved*: Enter pressing is ignored, row still looks like in edit mode. How to allow user to re-save changes in inline editing after error ?
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">var lastSel;
var decodeErrorMessage = function (jqXHR, textStatus, errorThrown) {
var html, errorInfo, i, errorText = textStatus + '\n' + errorThrown;
if (jqXHR.responseText.charAt(0) === '[') {
try {
errorInfo = $.parseJSON(jqXHR.responseText);
errorText = "";
for (i = 0; i < errorInfo.length; i++) {
if (errorText.length !== 0) {
errorText += "<hr/>";
}
errorText += errorInfo[i].Source + ": " + errorInfo[i].Message;
}
}
catch (e) { }
} else {
html = /<body.*?>([\s\S]*)<\/body>/.exec(jqXHR.responseText);
if (html !== null && html.length > 1) {
errorText = html[1];
}
}
return errorText;
};$(function () {
var grid = $("#grid");
grid.jqGrid({
url: '<%= ResolveUrl("~/Grid/GetData?_entity=Strings")%>',
scroll: 1,
datatype: "json",height: 350,
width: 740,
mtype: 'POST',colModel: [
{ name: 'Source', editable: true },
{ name: 'Est', editable: true
},
{ name: 'Lvl', editable: true },
{ name: 'Istopic', editable: true },
{ name: 'Critical', editable: true }
],ondblClickRow
: function (id) {
if (id && id !== lastSel) {
grid.restoreRow(lastSel);
lastSel = id;
}
grid.editRow(id, true);},
autoencode: true,
gridview: true,
pager: '#pager',
sortname: 'est',
viewrecords: true,
sortorder: "asc",
caption: "Test",
editurl: '<%= ResolveUrl("~/Grid/Save?_entity=Strings")%>',
multiselect: true,
multiboxonly: true,loadError: function (jqXHR, textStatus, errorThrown) {
// remove error div if exist
$('#' + this.id + '_err').remove();
// insert div with the error description before the grid
grid.closest('div.ui-jqgrid').before(
'<div id="' + this.id + '_err" style="max-width:' + this.style.width +
';"><div class="ui-state-error ui-corner-all" style="padding:0.7em;float:left;"><span class="ui-icon ui-icon-alert" style="float:left; margin-right: .3em;"></span><span style="clear:left">' +
decodeErrorMessage(jqXHR, textStatus, errorThrown) + '</span></div><div style="clear:left"/></div>')
},loadComplete: function () {
// remove error div if exist
$('#' + this.id + '_err').remove();
}});
grid.navGrid("#pager", { edit: true, add: true, del: true, refresh: true, search: true, searchtext: "Find" },
{}, {}, { },
{multipleSearch: true, overlay: false }
);grid.jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: 'cn' });
grid.jqGrid('navButtonAdd', '#pager',
{ caption: "Filter", title: "Toggle",
buttonicon: 'ui-icon-pin-s',
onClickButton: function () { grid[0].toggleToolbar(); }
});
});
</script>
<table id="grid">
</table>
<div id="pager">
</div>
</asp:Content>
21:19

10/08/2009

I posted you the link to example which has no editing. It get only data from the server. If you use some kind of editing you should of course implement additional event handlers or in case of inline editing use errorfunc additional parameters of editRow. Look at the answer or another one for example.
Best regards
Oleg
23:59

05/05/2011

Thank you. In case or error my appli returns 4xx http error code.
Same issue is described in
/blog/?page_id=393&forum=1&topic=5672&watch=user
/blog/?page_id=393/help/ajax-validation-while-saving-an-inline-edit/
https://github.com/tonytomov/jqGrid/blob/master/js/grid.inlinedit.js
show two different names:
line 23 and 103 :
"restoreAfterErorr" : true
line 250:
if(o.restoreAfterError === true) {
I tried to use
function errorfunc(rowid, response) {
restoreAfterError = false;
restoreAfterErorr = false;
grid.restoreAfterError = false;
grid.restoreAfterErorr = false;
alert(response.responseText);
return true;
}
After error messagebox is shown but Enter key will not work. How to allow Enter key to save again after error ?
10:41

05/05/2011

I also noticed anoter message in this form which wrote that Enter key is unbinded too early. How to fix this so that Enter/Esc are unbinded only if save was successfull ?
Your Filter class uses switch for every type. Maybe it is possible to use Convert.ChangeType instead of this to remove this switch as described in
11:01

10/08/2009

Sorry, but I have now too few time. So if you found an error you should post the bug report in the Bugs part of the forum.
By the way Tony is the developer of jqGrid not me. I use jqGrid in some of my projects and I help other (mostly on the stackoverflow.com) who use jqGrid, but it is only hobby for me.
Best regards
Oleg
Most Users Ever Online: 715
Currently Online:
60 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66