cannot get extjs grid to populate with proxy data call - asp.net-mvc

I have gone from incorporating extjs in my original asp.net application which worked when hardcoding any data stores and binding them to the charts/grids. When I tried proxy url calls or even fetching the data from code behind and wrapping in json I still do not get the data into the grid. So I gave up and went with extjs and nodejs and still using mongodb; this worked perfectly but I still have to learn to create a better UI using express/jade etc which is a different project now. But then I came across using MVC with extjs and with a sample project tried the same thing (the sample had hardcoded data) and I cannot for the life of me get it to display the data.
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.state.*'
]);
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.define('User', {
extend: 'Ext.data.Model',
fields: [
{ name: 'username', type: 'string' }
]
});
Ext.define('UserStore', {
extend: 'Ext.data.Store',
model: 'User',
autoload: true,
proxy: {
type: 'ajax',
url: '/dashboard.aspx/getDBData',
reader: {
type: 'json',
root: 'users'
},
listeners:
{
exception: function (proxy, response, operation) {
Ext.MessageBox.show(
{
title: 'REMOTE EXCEPTION',
msg: operation.getError(), icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK
});
}
}
}
});
var myStore = Ext.getStore('UserStore');
the url I am including here is the codebehind function that I initially tried which accesses the mongodb and returns json result. Not working.
Now from the extjs node.js application I have results coming into localhost:3000/userlist which returns a list from mongodb and displays it as follows:
extends layout
block content
h1.
User List
u1
each user, i in userlist
li
a(href="mailto:#{user.email}")= user.username
Now would it be possible to use the same server and call the base url and then change the route.js file to return the mongodb json result or call the mongodb localhost:27017 and get a result. Really confused here
exports.index = function(db) {
return function(req, res) {
var collection = db.get('usercollection');
collection.find({},{}, function(e,docs){
res.render('userlist', {
"userlist" : docs
});
});
};
};
EDIT:
First thing I realized from asp.net perspective was that I was not calling a webservice just a codebehind method. Any comments will still be appreciated.
EDIT 2:
{"connTime":null,"userName":"101591196589145","clientName":null,
"feedUrl":null,"dconnTime":null,"errMessage":null,"ip":null}

You have identified a root in your store as 'users'
reader: {
type: 'json',
root: 'users'
},
But there is no root in your returned json such as:
{"users":[{"connTime":null,"userName":"101591196589145","clientName":null,
"feedUrl":null,"dconnTime":null,"errMessage":null,"ip":null}]}

Related

Fetching data on IOS react redux

I'm building my first application using react and redux, and for some reason, the structure of the data received on a Async action is behaving different on the IOS (safari).
This action makes the fetch (cross-fetch) request:
export function fetchTransactions() {
return (dispatch) => {
dispatch(requestTransactions());
return fetch('/getTransactions', {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Cache: 'no-cache',
},
credentials: 'same-origin',
})
.then(
response => response.json(),
error => console.log('An error occurred.', error),
)
.then(json => dispatch(receiveTransactions(json.dados)));
};
}
And the receive action is:
export const RECEIVE_TRANSACTIONS = 'RECEIVE_TRANSACTIONS';
export function receiveTransactions(data) {
return {
type: RECEIVE_TRANSACTIONS,
data,
};
}
Reducer
case 'REQUEST_TRANSACTIONS':
return Object.assign({}, {...state}, {isFetching: true});
case 'RECEIVE_TRANSACTIONS':
return Object.assign({}, {...state}, {data: action.data}, {isFetching: false});
Now I'll show you the results on Firefox running on linux:
It works as expected, the transaction data is present on the array called data.
Here is a print screen from a Safari emulator:
As you can see, the are duplicate fields and other fields. This behavior is causing the application to not work correctly. Any ideas? Thank you very much and sorry about the English thing.
#edit-------------------------------------------
Running the application on other emulator, results in a good state but the data isn't displayed on the table as you can see bellow:
As you can see, there are 100 data objects in the array, and nothing on the table, this is not happening on firefox or chrome.

Displaying huge amount of data (in json object) in Kendo UI tree view. Give stack overflow error with huge records

I need to display all the records in a kendo view tree view at one go. Means at load of tree, I want all the nodes of my hierarchical data to be displayed. When data is less, I am getting no issue. But when my data is high, I am getting stack overflow error at line number:3, say.
When I debug the visual studio code, I get : "0x800a001c - Microsoft JScript runtime error: Out of stack space"
Actually what is happening, when a child node is displayed, kendo checks for the parent node. So if we have multiple child nodes, recursive calls are happening to get the parent node. With huge data, recursive calls are huge. Hence getting stack overflow error. Can anyone here help me out what I should change in my code.
I am using MVC for this. And 'treeData' contains json data.
The data is coming from the service in hierarchical format.
_intializeStudentTree: function () {
var abc = this;
var treeData = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: "controller1/method1",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8"
},
parameterMap: function (options) {
options['StudentID'] = abc.options.list.StudentId;
options['StudentDetails'] = abc.options.list.StudentDetails;
return JSON.stringify(options);
}
},
schema: {
model: {
children: "ChildRecords"
}
}
});
abc.subscriptionListTree = abc.element.find('.tree-view').kendoTreeView({
template: kendo.template($("#temp-treeview").html()),
animation: {
expand:false
},
dataSource: treeData,
dataTextField: ["StudentLevel"],
loadOnDemand: false,
dataBound: function () {
thiz.subscriptionListTree.expand(".k-item");
}
}).data('kendoTreeView');
},

JQuery AJAX Call to MVC action , asking the Credentials in Windows Server 2008R2

I have a jquery ajax POST to a MVC Action (which returns action result). In that i retrive record from DB and store in Session and return partial view result . On my machine this works well, when deployed it in Windows Server 2008 R2 , A popup appears in the browser asking me to enter credentials (authentication required).
The jquery call:
var data = $('#SearchForm').serialize();
window.location.hash = '#/' + data;
$.ajax({
url: '/PromotionManagement/PromotionsSearch',
type: 'POST',
data: data,
beforeSend: function (xhr) {
$('#search-result').hide();
$('#divresetCancel').hide();
$('#divwait').show();
// console.log('before sending request...');
},
error: function () {
//console.log("error processing request...");
},
success: function (data) {
debugger;
//console.log("successfully processed request...");
$('#search-result').html(data);
$('#search-result').show();
$('#divwait').hide();
$("#validation").html("");
if ($(data).html() == '\n No Records Found \n ') {
$('#divresetCancel').hide();
}
else {
$('#divresetCancel').show();
}
}
});
MVC Action :
[HttpPost]
public ActionResult PromotionsSearch(string list,string query)
{
//code to retrive the data from DB.
Session["SearchPerameters"] = objSearchPerameters;
return PartialView("PromotionsGrid", Promotions);
}
I referred this link and stopped storing the data in Session.
Even though it didn't work .
Can you pls suggest me what is missing..
any help can be greatly appreciated.
This issue got fixed by changing the AJAX call url: '/PromotionManagement/PromotionsSearch' [controllerName/ActionName] as 'PromotionsSearch' [Only Action Name].

Sencha touch XML response to JSON

I have recently started a project in Sencha touch with existing Web-services.
Being very new to the technology, I am facing certain issues in accomplishing some functionality.
Problem
I have to call login service and the request goes like:
http://domain.sub.com/Service.asmx/LoginService?body={"Username":"maj#smaj.com","Password":"p12345","Token":122112321123212123,"Method":"Login","LabId":"(null)","Hash":"fr3f33f3334348u8yy8hfuhdu8bdy7y89u89x8998c89789c87d78r9","DeviceType":"iPhone Simulator","DeviceId":"91BF3299-A94C-5AD3-9C35-A5C9BBBB6AA8","ApplicationType":"iPhone","Id":"998390494"}
but the response is coming in XML format as:
RESPONSE:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://domain2.sub2.com/MobileWebService/">{"Id":"null","Message":"Logged In.","Status":true,"LoggedIn":true}</string>
I have to parse this xml to json to get : {"Id":"null","Message":"Logged In.","Status":true,"LoggedIn":true} out of the response.
then use the Status, LoggedIn and Id to verify the login.
My Idea
I am not sure whether its right, I am trying to create two stores, xmlStore and JsonStore.
??
How will I store the xml response inside a string.
How Will I pass this string to Json Store (at the place of url?)
I may sound very naive to this, but this is my problem ;)
Please guide.
EDIT:
I realized tha I am diving cross domain request.
is that what is causing problems or confusion. How to deal with it suppose I did not had cross domain requests?
If you are doing cross domain requests use scripttag in your proxy in place of ajax. Here is a json example
ex.
mApp.stores.onlineStore = new Ext.data.Store({
model: 'XPosts',
proxy: {
type: 'scripttag',
url : 'http://domain.com/data.json',
reader: new Ext.data.JsonReader({
root: 'pages'
}),
timeout: 3000,
listeners: {
exception:function () {
console.log("onlineStore: failed");
},
success: function(){
console.log("onlineStore: success");
}
}
},
autoLoad: true
});
Offline store:
mApp.stores.offlineStore = new Ext.data.Store({
model: 'XPosts',
proxy: {
type: 'localstorage',
id: 'appdata',
reader: new Ext.data.JsonReader({
root: 'pages'
})
},
autoLoad: true
});
Then, in your launch :
this.stores.onlineStore.addListener('load', function () {
console.log("onlineStore: online");
mApp.stores.offlineStore.proxy.clear();
console.log("offlineStore: cleared");
this.each(function (record) {
console.log("offlineStore: adding record");
mApp.stores.offlineStore.add(record.data)[0];
});
mApp.stores.offlineStore.sync();
console.log("offlineStore: synced");
mApp.stores.offlineStore.load();
});
this.stores.onlineStore.load();
May have some bugs so beforewarned!

ASP.NET MVC + jqGrid without AJAX

I have an ASP.NET MVC application which is executing a search against a products database. I want to display the results in a jqGrid using the TreeGrid module. I don't really need the grid to be AJAX-y because the data is static and it is small enough that it can all be sent to the client at once.
First question: how do I set up jqGrid so that instead of pulling the JSON data from a URL it just looks in a JS variable or something?
Secondly, what is the most appropriate way to get ASP.NET MVC to put JSON data into a JavaScript variable? I already have the List in my controller and just want to somehow get it out into a JS variable after JSON-ing it.
Or am I fighting against the current too much and just accept the AJAX-y way that jqGrid seems to want to work?
Thanks,
~ Justin
Here is how to display a jqGrid tree using a JavaScript function.
$(document).ready(function() {
TreeDemo.setupGrid($("#tree"));
});
TreeDemo = {
data: { A: ["A1", "A2"], B: ["B1", "B2"] },
setupGrid: function(grid) {
grid.jqGrid({
colNames: ['Name'],
colModel: [
{ name: 'Name', index: 'Name', width: "250em" }
],
datatype: TreeDemo.treeData,
loadui: "none",
sortname: 'Number',
treeGrid: true,
treeGridModel: "adjacency",
sortorder: "asc"
})
},
treeData: function(postdata) {
var items = postdata.nodeid ? TreeDemo.data[postdata.nodeid] : TreeDemo.data;
var i = 0;
var rows = new Array();
for (val in items) {
var isLeaf = postdata.nodeid != undefined;
rows[i] = {
Name: val,
Id: val,
level: postdata.nodeid ? 1 : 0,
parent: postdata.nodeid || null,
isLeaf: isLeaf ? "true" : "false",
expanded: "false"
}
i++;
}
$("#tree")[0].addJSONData({
Total: 1,
Page: 1,
Records: 2,
Rows: rows
});
}
};
Note that there are lots of options for how you do this and my example is only one.
The way I would get the JSON into a JS var is to either:
Write a HTML Helper which emits a short script to the page.
Write an action which returns a JavaScriptResult to get the data in a file, if, for some reason, you can't have the data inline.
You create the JSON using the .NET JavaScript serializer. Look at the JsonResult.ExecuteResult in the MVC source code for an example.
See the Data Manipulation page in the jqGrid documentation wiki. There you'll find many ways to feed the data to the grid.
There is also a Table_to_jqGrid plugin that may be an useful option.

Resources