Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
How to convert search string to where clause in asp .net mvc
15/05/2011
09:51
Avatar
kobruleht
Member
Members
Forum Posts: 144
Member Since:
05/05/2011
sp_UserOfflineSmall Offline
jqGrid passes search string
 
{"groupOp":"AND","rules":[
{"field":"source","op":"eq","data":"searchvalue1"},
{"field":"est","op":"eq","data":"searcvvalue2"}
]}
 
as filters parameter to controller.
 
        public ActionResult GetData(string sidx, string sord, int page, int rows, string filters)
 
rules array may contain many and clauses
op is operator.
How to convert it into .net data type and to sql WHERE clause ?
This string should be converted to
source='searchvalue1' and est='searchvalue2'
15/05/2011
12:30
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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/05/2011
15:32
Avatar
kobruleht
Member
Members
Forum Posts: 144
Member Since:
05/05/2011
sp_UserOfflineSmall Offline

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>

15/05/2011
21:19
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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

15/05/2011
23:59
Avatar
kobruleht
Member
Members
Forum Posts: 144
Member Since:
05/05/2011
sp_UserOfflineSmall Offline

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 ?

16/05/2011
10:41
Avatar
kobruleht
Member
Members
Forum Posts: 144
Member Since:
05/05/2011
sp_UserOfflineSmall Offline

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

http://www.codeproject.com/KB/.....x3586944xx

16/05/2011
11:01
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information