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
JQGrid Search: Need to do the search on hidden fields in JQgrid
05/12/2010
18:31
Avatar
dednrimer
Tx
New Member
Members
Forum Posts: 1
Member Since:
05/12/2010
sp_UserOfflineSmall Offline

Hi

working on JQ grid search popup. I have a JQGrid and I need to customize the search pop up. I am now fetching the results from the database and converting it into JSon string and displaying in the grid based on the equals, begins with operator, value in the filtes etc.. Search is  working fine for the collumns that are displayed in the grid but I have a few fields that are  hidden in the grid. I need to make it work for the hidden fields, which are displayed in the dropdown. Need code to get a handle on the search call and manipulate it?. Posting below my code:

Search is working fine for:

 { name: 'LastName', width: 150, sortable: true, search: true, searchoptions: { sopt: ['eq', 'bw', 'ew', 'cn']} },
 { name: 'FirstName', width: 150, sortable: true, search: true, searchoptions: { sopt: ['eq', 'bw', 'ew', 'cn']} },

I need to do the search based on the hidden fields ('Acct#','Accnt' ) on the grid: Can you pl. help with some code sample?. New to JQGrid. Not sure how to do it.

 { name: 'Acct#', width: 20, hidden: true, searchoptions: { searchhidden: true, sopt: ['eq', 'bw', 'ew', 'cn']} },
 { name: 'Accnt', width: 100, hidden: true, searchoptions: { searchhidden: true, sopt: ['eq', 'bw', 'ew', 'cn']} }

Here is the code snippet in my aspx file:

//Set up code in ready function
            jQuery("#jqVifyConts").jqGrid({
                // setup custom parameter names to pass to server
                prmNames: {
                    search: "isSearch",
                    nd: null,
                    rows: "numRows",
                    page: "page",
                    sort: "sortField",
                    order: "sortOrder"
                },
                // setup ajax call to webmethod
                datatype: function(postdata) {
                    jQuery(".loading").show();
                    var containerId = "<%=ClientID%>";
                    document.getElementById(containerId + "_hidSelectedPageIndex").value = postdata.page;
                    var hidSelectedContact = document.getElementById(containerId + "_hidSelectedContactRowInfo");
                    if (hidSelectedContact != null && hidSelectedContact.value != '') {
                        var pgindx = "<%=JQSelectedPageIndx%>";
                        if (pgindx != null && pgindx != '')
                            postdata.page = parseInt(pgindx);
                        jQuery('#jqVifyConts').setSelection(hidSelectedContact, true);
                        hidSelectedContact.value = '';
                    }
                    var hidSelectedDupNewemail = document.getElementById(containerId + "_hidDupNewemail");
                    if (hidSelectedDupNewemail != null && hidSelectedDupNewemail.value != '') {
                        searchStringval = hidSelectedDupNewemail.value;
                        searchFieldval = "Email";
                        searchOperval = 'eq';
                        jQuery("#jqVifyConts").appendPostData({ isSearch: true, searchString: searchStringval, searchField: searchFieldval, searchOper: searchOperval, pkey: akey, pvalue: akeyValue, plogin: aloginValue, pmodkey: amodKey, pselctdVal: aSelctValue });
                        hidSelectedDupNewemail.value = '';
                    }
                    else {
                        if (!postdata.isSearch) {
                            jQuery("#jqVifyConts").appendPostData({ searchString: '', searchField: '', searchOper: '', pkey: akey, pvalue: akeyValue, plogin: aloginValue, pmodkey: amodKey, pselctdVal: aSelctValue });
                        }
                    }
                    jQuery.ajax({
                        url: '<%= ResolveClientUrl("~/WebServices/abcService.asmx/LAccttCctsForVefyCntts")%>',
                        type: "POST",
                        contentType: "application/json; charset=utf-8″,
                        data: JSON.stringify(postdata),
                        dataType: "json",
                        success: function(data, st) {
                            if (st == "success") {
                                var grid = jQuery("#jqVifyConts")[0];
                                grid.addJSONData(JSON.parse(data.d));
                            }
                        },
                        error: function(data, st) {
                            alert('An error has occured retrieving data!');
                        }
                    });
                }, //datatype: function(postdata)
                height: 125,
                // this is what jqGrid is looking for in json callback
                jsonReader: {
                    root: "rows",
                    page: "page",
                    total: "totalpages",
                    records: "totalrecords",
                    cell: "cell",
                    id: "id", //index of the column with the PK in it 
                    userdata: "userdata",
                    repeatitems: true
                },
                colNames: ['ID', 'ContID', 'Last Name', 'First Name', 'xx/xxx', 'Phone Number', 'Email', 'Contact Type', 'Acct#', 'Accnt', 'Job Title', ],
                colModel: [
                    { name: 'ID', width: 10, hidden: true },
                    { name: 'ContID', width: 10, hidden: true },
                    { name: 'LastName', width: 150, sortable: true, search: true, searchoptions: { sopt: ['eq', 'bw', 'ew', 'cn']} },
                    { name: 'FirstName', width: 150, sortable: true, search: true, searchoptions: { sopt: ['eq', 'bw', 'ew', 'cn']} },
                    { name: 'Prefix', width: 60, sortable: true, search: true, searchoptions: { sopt: ['eq', 'bw', 'ew', 'cn']} },
                    { name: 'WorkPhone', width: 100, sortable: true, search: true, searchoptions: { sopt: ['eq', 'bw', 'ew', 'cn']} },
                    { name: 'Email', width: 150, sortable: true, search: true, searchoptions: { sopt: ['eq', 'bw', 'ew', 'cn']} },
                    { name: 'Unauthorized', width: 100, sortable: true, search: true, searchoptions: { sopt: ['eq', 'bw', 'ew', 'cn']} },
                    { name: 'Acct#'', width: 20, hidden: true, searchoptions: { searchhidden: true, sopt: ['eq', 'bw', 'ew', 'cn']} },
                    { name: 'Accnt', width: 100, hidden: true, searchoptions: { searchhidden: true, sopt: ['eq', 'bw', 'ew', 'cn']} },
                    { name: 'Job Title', width: 50, hidden: true, searchoptions: { searchhidden: true, sopt: ['eq', 'bw', 'ew', 'cn']} }
                ],
                rowNum: 5,
                rowList: [5, 10, 20, 30],
                sortname: "ID",
                sortorder: "asc",
                pager: jQuery("#verifyConctpager"),
                viewrecords: true,
                imgpath: '<%= ResolveClientUrl("~/themes/redmond/images") %>',
                caption: "",
                gridComplete: function() {
                    var containerId = "<%=ClientID%>";
                    jQuery(".loading").hide();
                    var ids = jQuery('#jqVerifyContacts').jqGrid('getDataIDs');
                    if (ids.length > 0) {
                        var rowId = jQuery("#jqVifyConts").getCell(ids[0], 'ID');
                        var existselectrowID = "<%=JQExistSelectedContact%>";
                        if (existselectrowID.toString().length > 0) {
                            jQuery('("#jqVifyConts").setSelection(existselectrowID, true);
                        }
                        else {
                            //Set the 1 Row as Default one
                            jQuery("#jqVifyConts").setSelection(rowId, true);
                        }
                    }
                },
                onSelectRow: function(ID) {
                    var defaultpagesize = 5;
                    var containerId = "<%=ClientID%>";
                    document.getElementById(containerId + "_hidSelectedContactRowInfo").value = ID;
                    var verSelectedRowId = document.getElementById(containerId + "_hidSelectedContactRowInfo").value;
                },
                onPaging: function(pgButton) {
                    var containerId = "<%=ClientID%>";
                    document.getElementById(containerId + "_hidSelectedContactRowInfo").value = "";
                }
            }).jqGrid('navGrid', '#verifyContactpager', { edit: false, add: false, del: false, refresh: true, refreshtext: "Refresh", search: true, searchtext: "Search" },
     {}, // default settings for edit
     {}, // add
     {}, // delete
     {closeOnEscape: true, closeAfterSearch: true }, //search
     {}
 )//'navGrid'
  }     };

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
34 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