Forum
I have an issue with errors on the server, like for example when the user selects to search by ID, the "contains" option is not really applicable as I use NHibernate Criterias which do not allow this kind of criteria for reasons I don't want to clutter this discussion with. So I also did not want an alert after LoadError, especially since I "tune" my search to return the previous result set if the search is "invalid" on my server so no LoadError happens. Below is the code updates I made to jqGrid to display a message box below the search line that is popolated from the server in a "Message" property that I added to the Jsonreader. It works great, feel free to add it to the next release it sure helped me.
- myjQuery.js file:
jsonReader:{
root: "Addresses",
page: "CurrentPage",
total: "TotalPages",
records: "TotalRecords",
message: "Message",
repeatitems: false,
id: "0"
},
- grid.css
/* Added by Renso to support messages from the server concerning the search results*/
div.modalwin.jqmWindow.jqmID1 div.modalcontent table tr#msgrow td input#rsltmsg {
margin: 2px;
width: 98%;
font-size: 10px;
color: #15428B;
}
- grid.formedit.js
$.fn.extend({
searchGrid : function ( p ) {
p = $.extend({
top : 0,
left: 0,
width: 380, //Renso: changed from 360
height: 90, //Renso: changed from 70
modal: false,
// field and buttons
var sField = "<input id='sval' class='search' type='text' size='20' maxlength='100'/>";
var bSearch = "<input id='sbut' class='buttonsearch' type='button' value='"+p.Find+"'/>";
var bReset = "<input id='sreset' class='buttonsearch' type='button' value='"+p.Reset+"'/>";
var tmsg = "<input id='rsltmsg' class='message' type='text' value='' readOnly=true'/>";
//Renso: var cnt = $("<table width='100%'><tbody><tr><td>"+cNames+"</td><td>"+sOpt+"</td><td>"+sField+"</td><td>"+bSearch+"</td><td>"+bReset+"</td></tr></tbody></table>");
//Renso: updated by adding row for comment
var cnt = $("<table width='100%'><tbody><tr><td>"+cNames+"</td><td>"+sOpt+"</td><td>"+sField+"</td><td>"+bSearch+"</td><td>"+bReset+"</td></tr><tr id='msgrow'><td colspan=5>"+tmsg+"</input></td></tr></tbody></table>");
grid.base.js
endReq();
updateMessage(); //Renso: added to update the message for errors in searching
updatepager();
};
var updateMessage = function() {
if(ts.p.message) {
$('div.modalwin.jqmWindow.jqmID1 div.modalcontent table tr#msgrow td input#rsltmsg').val(ts.p.message );
}
};
var updatepager = function() {
That's it.
Left out an important piece in grid.base:
var addJSONData = function(data,t) {
if(data) { $("tbody tr:gt(0)", t).remove(); } else { return; }
var row,f=[],cur,gi=0,si=0,drows,idn,rd=[],cn=(ts.p.altRows===true) ? 'alt':'';
ts.p.page = data[ts.p.jsonReader.page];
ts.p.lastpage= data[ts.p.jsonReader.total];
ts.p.records= data[ts.p.jsonReader.records];
//Renso: added message property for handling server side message during searches
ts.p.message= data[ts.p.jsonReader.message];
If you want to add hiding and displaying of the message based on content you can also do in grid.base.js:
var updateMessage = function() {
if(ts.p.message) {
if(ts.p.message.length > 0) {
$('div.modalwin.jqmWindow.jqmID1 div.modalcontent table tr#msgrow td input#rsltmsg').val(ts.p.message).show();
return;
}
}
$('div.modalwin.jqmWindow.jqmID1 div.modalcontent table tr#msgrow td input#rsltmsg').val("").hide();
};
08:45
Moderators
30/10/2007
Hello,
I do not answerd of this since I think you will find a more easy solution.
I do not known which version do you use but lets look at jsonReader
and xmlReader.
var jReader = {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: true,
cell: "cell",
id: "id",
userdata: "userdata",
subgrid: {root:"rows", repeatitems: true, cell:"cell"}
The same can be achieved without touch the code using the userdata
The problem was that in the search dialog there was no place for
the errors. In the upcomming release I have added this and so you can
easy add the custom message here.
Also I have added a special message function for this purpose.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
40 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