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_Related Related Topics sp_TopicIcon
Pass parameters to Wcf restful service through JQGrid urgent
Tags: wcfjqgrid
27/09/2012
00:21
Avatar
manjushree.nimbalkar
Member
Members
Forum Posts: 9
Member Since:
26/09/2012
sp_UserOfflineSmall Offline

Hello,

I have WCf service (it is normal WCF service not Ajax enabled) which accepts various parameter. Through Jqgrid in SerializeGridData I can send the parameters to Ajax enabled wcf service. But my normal WCF service dosen't work with this. Is there any way how I can send parameters to my WCF service. I tried lot of things but didn't work.

Please help.

Thanks in advance.

Manju

27/09/2012
13:12
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Sorry, but you do not provide a example?

Why your service can not accept this parameters.

If yyou try with pure ajax does the service accept parameters?

Not sure that I understand the problem

Regards

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.

27/09/2012
17:27
Avatar
manjushree.nimbalkar
Member
Members
Forum Posts: 9
Member Since:
26/09/2012
sp_UserOfflineSmall Offline

Thanks for the reply. Yes with pure Ajax service accept the parameter. 

Let me give the example:

In VS 2010 I have added WCF service.

Public Function GetInfo(sidx As String, sord As String, page As Integer, rows As Integer, infoid As String, nd As Integer, _search As Boolean) 
As InfoDataForJqGrid Implements IInfo.GetInfo

End Function

The binding used is "webHttpBinding".

In Html i'm trying to send the parameter to the WCF service. But not sure how to do this. I have used below option:
 
function loadGrid() {
    jQuery("#tblInfo").jqGrid({
        url: 'Services/Service.svc/getInfo',
        postData: {
            infoid : function () {
                return "1"; // $("#infoid ").val();
            }
        },
        mtype: 'POST',
        datatype: 'json',
        ajaxGridOptions: { contentType: "application/json" },
        serializeGridData: function (postData) {
            var propertyName, propertyValue, dataToSend = {};
            for (propertyName in postData) {
                if (postData.hasOwnProperty(propertyName)) {
                    propertyValue = postData[propertyName];
                    if ($.isFunction(propertyValue)) {
                        dataToSend[propertyName] = propertyValue();
                    } else {
                        dataToSend[propertyName] = propertyValue
                    }
                }
            }
            return JSON.stringify(dataToSend);
        },
        jsonReader: {
            root: "d.rows",
            page: "d.page",
            total: "d.total",
            records: "d.records"
        },
        colNames: ['Code', 'Title', 'Price', 'Product Group', 'Edit', 'Status'],
        colModel: [
                    { name: 'Code', index: 'Code', width: 75, align: 'center' },
                    { name: 'Title', index: 'Title', width: 40, align: 'center' },
                    { name: 'Price', index: 'Price', width: 55 },
                    { name: 'Product Group', index: 'Product Group', width: 100 },
                    { name: 'Edit', index: 'Edit', width: 40 },
                    { name: 'Status', index: 'Status', width: 40}],
        pager: '#pager',
        rowList: [10, 20, 30],
        sortname: 'Code',
        sortorder: 'desc',
        rowNum: 10,
        loadtext: "Loading....",
        shrinkToFit: false,
        multiselect: true,
        emptyrecords: "No records to view",
        //width: x - 40,
        height: "auto",
        rownumbers: true,
        //subGrid: true,
        caption: 'Products'
    });
    jQuery("#prodgrid").jqGrid('navGrid', '#pager',
                { edit: false, add: false, del: true, excel: true, search: false });
    //});
}


Now in the seralizeGridData i get the proper string, but service is not getting called.
It gives error "500 INternal server error". This works fine if I have Ajax enabled wcf service.
Please let me know what I'm missing here.
Thanks for quick reply.
Manju
28/09/2012
08:46
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

serializeGridData should return the same data as it accept as parameter - i.e not string - with other words replace

return JSON.stringify(dataToSend);

with

return dataToSend;

Regards

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.

28/09/2012
17:10
Avatar
manjushree.nimbalkar
Member
Members
Forum Posts: 9
Member Since:
26/09/2012
sp_UserOfflineSmall Offline

Hello,

Thanks for quick reply. I have already tried sending data with and without JSON.stringify.

Service is not called somehow. IN normal case, if I have to send parameters to the service method I use

"data" parameter. Is it something related to that?

Waiting for reply.

Thanks,

Manjushree

29/09/2012
00:47
Avatar
manjushree.nimbalkar
Member
Members
Forum Posts: 9
Member Since:
26/09/2012
sp_UserOfflineSmall Offline

Hello,

The problem is solved. Thanks for the reply in earlier post.

Manjushree

29/09/2012
10:33
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Just for the record - please post what was the problem and how you have resolved it.

Thank you.

Regards

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.

01/10/2012
21:15
Avatar
manjushree.nimbalkar
Member
Members
Forum Posts: 9
Member Since:
26/09/2012
sp_UserOfflineSmall Offline

Hello,

I was not able to pass parameters to WCF service. This is how i did it:

function successFunction(jsondata) {

    var thegrid = jQuery("#tblInfo")[0];

    thegrid.addJSONData(jsondata.GetInfoResult);

}

function getInfo(pdata) {

    var data = [];

    data.push({ Key: "rows", Value: pdata.rows });

    data.push({ Key: "page", Value: pdata.page });

    data.push({ Key: "sidx", Value: pdata.sidx });

    data.push({ Key: "sord", Value: pdata.sord });

    data.push({ Key: "ddlinfostatus", Value: "1" });

    data.push({ Key: "search", Value: pdata._search });

    var dictObject = { nvp: data };

    var _url = "Services/Info.svc/GetInfo"

    $.ajax({

        url: _url,

        data: JSON.stringify(dictObject),

        dataType: "json",

        type: "POST",

        contentType: "application/json; charset=utf-8",

        success: successFunction,

        error: function (jsondata) {

            alert('error');

        }

    });

}

function loadGrid() {

    jQuery("#tblinfo").jqGrid({

       datatype: function (pdata) {

            getInfo(pdata);          // calls the function above with 'postData' 

        },

        colNames: ['Sk', Id', ],

        colModel: [{ name: sk', index: sk', width: 20 },

                    { name: 'id', index: 'id', width: 200 }],

        jsonReader: { repeatitems: false,

            root: function (obj) { return JSON.parse(obj.rows); },

            page: function (obj) { return obj.page; },

            total: function (obj) { return obj.total; },

            records: function (obj) { return obj.records; },

            id: '0',

            cell: ''

        },

        width: 500,

        height: 200,

        rowList: [10, 20, 30],

        rowNum: 10,

        sortname: 'sk',

        emptyrecords: "No records to view",

        sortorder: "asc",

        viewrecords: true,

        pager: '#pager',

        caption: "",

        loadtext: "Loading....",

        sortable: true

    });

}

Thanks,

Manju

01/10/2012
22:14
Avatar
manjushree.nimbalkar
Member
Members
Forum Posts: 9
Member Since:
26/09/2012
sp_UserOfflineSmall Offline

Hello,

With the above code now I want to dynamically add the columns. The colNames and colModel will come through the service. Will you please let me know how to do it?

Thanks in Advance,

Manju

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

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