0

Hello I'm trying to bind a jqxGrid but nothing works at the moment. Some information to start: I've a data access project that uses Entity Framework to access database. The data access project methods are called by custom SharePoint 2013 WCF server. The WCF methods looks like

    public string GetData()
    {
        return new JavaScriptSerializer().Serialize(BL.GetData());
    }

BL.GetData() returns an IList that I format in JSON in the WCF service. If I navigate to the GetData method url I can see the JSON result so I suppose that this part works.

This my html page:

<script src="jquery-1.9.1.js"></script>
<script src="jqxbuttons.js"></script>
<script src="jqxcore.js"></script>
<script src="jqxdata.js"></script>
<script src="jqxdropdownlist.js"></script>
<script src="jqxgrid.columnsresize.js"></script>
<script src="jqxgrid.filter.js"></script>
<script src="jqxgrid.grouping.js"></script>
<script src="jqxgrid.js"></script>
<script src="jqxgrid.pager.js"></script>
<script src="jqxgrid.selection.js"></script>
<script src="jqxgrid.sort.js"></script>
<script src="jqxlistbox.js"></script>
<script src="jqxmenu.js"></script>
<script src="jqxscrollbar.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var source = {
            type: "GET",
            datatype: "json",
            datafields: [
                { name: 'Field1'},
                { name: 'Field2'},
            ],
            url: 'Service.svc/GetData',
            cache: false,
        };

        //Preparing the data for use    
        var dataAdapter = new $.jqx.dataAdapter(source, {
            contentType: 'application/json; charset=utf-8',
            downloadComplete: function (data, textStatus, jqXHR) { return data.d; }
        });

        $("#jqxgrid").jqxGrid({
            source: dataAdapter,
            columns: [
                { text: 'Field1', dataField: 'Field1' },
                { text: 'Field2', dataField: 'Field2' }]
        });
    });
</script>
<div id="jqxgrid">
</div>

The JSON looks like this:

[{
    "Field1": "Field1",
    "Field1": "Field1"
},
{
    "Field2": "Field2",
    "Field2": "Field2"
}]

What is wrong? Thank you

chenny
  • 769
  • 2
  • 17
  • 44
  • If you're using WCF, rather than returning a string, you need to return the list of objects themselves. WCF will format them for you using the data contract serializer. See [How do I return clean JSON from a WCF Service?](http://stackoverflow.com/questions/2086666/how-do-i-return-clean-json-from-a-wcf-service). – dbc Sep 08 '15 at 13:43
  • For entity framework, see also http://stackoverflow.com/questions/16791169/return-entity-framework-objects-from-wcf or maybe http://stackoverflow.com/questions/11558234/wcf-rest-service-json-and-using-my-model-data-with-entity-framework-database-f – dbc Sep 08 '15 at 13:48

0 Answers0