I have exhausted all my efforts in attempting to retrieve the JSON data from my webservice. Despite being able to view the JSON data in Fiddler, I am facing an issue where the data is not binding with the grid. Below is the code snippet that I have been working on.
Webservice (Mywebservice.asmx)
[WebService(Namespace = "http://myServiceLink.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class SmartlinkService : System.Web.Services.WebService
{
[WebMethod(CacheDuration = AppConsts.NONE)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false, XmlSerializeString = false)]
public List<SampleClass> GetTasks()
{
List<SampleClass> listSampleClass = new List<SampleClass>(){
new SampleClass{TaskId="1",TaskName="task1"},
new SampleClass{TaskId="2",TaskName="task2"},
new SampleClass{TaskId="3",TaskName="task3"},
new SampleClass{TaskId="4",TaskName="task4"}
};
return listSampleClass;
}
[Serializable]
public class SampleClass
{
public string TaskId { get; set; }
public string TaskName { get; set; }
}
}
User Control (UserControl.ascx)
<link href="Resources/extJS/resources/css/ext-all-debug.css" />
<script src="Resources/extJS/ext-all-debug.js" language="JavaScript" />
<script src="Resources/extJS/Ext.ux.AspWebAjaxProxy.js" ResourceType="JavaScript" />
<div class="section" runat="server" id="senchaGrid">
<h1 class="mhdr">
Project Tasks
</h1>
<div class="content">
<div class="swrap">
<%--sencha grid area--%>
<div id="topic-grid">
</div>
</div>
</div>
ExtJS Script Code
<script type="text/javascript" language="javascript">
/**********************************Sencha Grid Code START***********************************/
Ext.Loader.setConfig({ enabled: true });
Ext.Loader.setPath('Ext.ux', '../Resources/extjs/examples/ux');
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.panel.*',
'Ext.util.*',
'Ext.toolbar.Paging',
'Ext.ux.PreviewPlugin',
'Ext.ModelManager',
'Ext.layout.container.Border',
'Ext.tip.QuickTipManager'
]);
Ext.onReady(function () {
Ext.QuickTips.init();
// setup the state provider, all state information will be saved to a cookie
Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));
Ext.namespace('EXT');
Ext.define('myModel', {
extend: 'Ext.data.Model',
fields: ['TaskId', 'TaskName'],
id: 'TaskId'
});
var storeData = new Ext.data.Store(
{
autoLoad: true,
proxy: new Ext.ux.AspWebAjaxProxy({
url: '/ProjectManagement/Mywebservice.asmx/GetTasks',
actionMethods: {
read: 'POST'
},
reader: {
type: 'json',
model: 'myModel',
root: 'd'
},
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
})
});
//var pluginExpanded = true;
debugger;
var myGrid = Ext.create('Ext.grid.Panel', {
width: 1115, height: 500,
//title: 'Manage tasks',
store: storeData,
//disableSelection: true,
//stateful: true,
//stateId: 'stateGrid',
loadMask: true,
// grid columns
columns: [
{ text: 'TaskId', dataIndex: 'TaskId', header: 'Row #' },
{ text: 'TaskName', dataIndex: 'TaskName', header: 'Task Name' }
],
// paging bar on the bottom
bbar: Ext.create('Ext.PagingToolbar', {
store: storeData,
displayInfo: true,
displayMsg: 'Displaying tasks {0} - {1} of {2}',
emptyMsg: "No topics to display"
}),
renderTo: 'topic-grid'
});
// trigger the data store load
//store.load();
});
/**************************Sencha Grid Code END******************************/
Ext.ux.AspWebAjaxProxy.js
/// <reference path="/Scripts/ext-all-debug.js" />
Ext.define('Ext.ux.AspWebAjaxProxy', {
extend: 'Ext.data.proxy.Ajax',
require: 'Ext.data',
buildRequest: function (operation) {
var params = Ext.applyIf(operation.params || {}, this.extraParams || {}),
request;
params = Ext.applyIf(params, this.getParams(params, operation));
if (operation.id && !params.id) {
params.id = operation.id;
}
params = Ext.JSON.encode(params);
request = Ext.create('Ext.data.Request', {
params: params,
action: operation.action,
records: operation.records,
operation: operation,
url: operation.url
});
request.url = this.buildUrl(request);
operation.request = request;
return request;
}
});
The JSON data retrieved from the server and inspected in Fiddler:
{"d":[{"__type":"Mywebservice+SampleClass","TaskId":"1","TaskName":"task1"},{"__type":"Mywebservice+SampleClass","TaskId":"2","TaskName":"task2"},{"__type":"Mywebservice+SampleClass","TaskId":"3","TaskName":"task3"},{"__type":"Mywebservice+SampleClass","TaskId":"4","TaskName":"task4"}]}
Despite no exceptions being thrown in the browser, I am perplexed as to why the grid is not binding with the data properly. It merely displays an empty grid with column headers and a paging toolbar. If anyone could shed light on what might be missing here, it would be greatly appreciated.
Please assist. Thank you!