Problem with EXTJS 4 Grid - asp.net

I am trying to load a JSON string into an EXTJS grid. The error i am getting is Uncaught TypeError: Cannot read property 'prototype' of undefined from ext-all-debug.js.
Here is my code for the js file.
$(document).ready(function () {
var store = new Ext.data.Store(
{
proxy: new Ext.data.HttpProxy(
{
url: 'http://localhost:3197/Home/GetSecondaryOfferings'
}),
reader: new Ext.data.JsonReader(
{
root: 'items',
totalProperty: 'totalCount',
id: 'id',
fields: [{name:'CUSIP', mapping: 'CUSIP'},'DESCRIPTION','COUPONRATE','ASKPRICE']
})
});
store.load();
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{ header: 'CUSIP', dataIndex: 'CUSIP'},
{ header: 'Description', dataIndex: 'DESCRIPTION', width: 100 },
{ header: 'COUPONRATE', dataIndex: 'COUPONRATE', width: 100 },
{ header: 'ASKPRICE', dataIndex: 'ASKPRICE', width: 100 }
],
renderTo: 'example-grid2',
width: 1000,
autoHeight: true,
title: 'Employees'
});
});
Here is a sample of the JSON file that is returned, it does get returned....
{"items":[{"CUSIP":"989701AL1","DESCRIPTION":"ZIONS BANCORPORATIONSB NT 5.65000% 05/15/2014","COUPONRATE":" 5.650","ASKPRICE":" 104.450"}],"totalCount":3316}
For good measure, here is the .cshtml file. I am using ASP MVC.
#{
ViewBag.Title = "About Us";
}
<h2>About</h2>
<p></p>
#section JavaScript
{
<link href ="#Url.Content("~/Content/resources/css/ext-all.css")" rel="Stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href=#Url.Content("~/Content/resources/css/ext-all.css") />
<link rel="stylesheet" type="text/css" href=#Url.Content("~/Content/examples/shared/example.css") />
<script type="text/javascript" src=#Url.Content("~/Content/bootstrap.js")></script>
<script type="text/javascript" src=#Url.Content("~/Content/examples/grid/FIO8472-JSON.js")></script>
}
<div id="example-grid"></div>
<div id="example-grid2"></div>
Any Help is appreciated.

You are launching the javascript code using jQuery. ExtJS has its own code launcher. Your code needs to be within onReady() method.
Example:
Ext.onReady(function() {
var store = new Ext.data.Store(
.
.
. // rest of your code
});
Since you are using ExtJs4, try the new MVC application architecture as well.

your store need a model
like this :
Ext.define('AM.model.User', {
extend: 'Ext.data.Model',
fields: ['id', 'name', 'email']
});
look a this exemple of the New store définition in extjs 4 '( from simple app example)
and try use MVC application architecture
Ext.define('AM.store.Users', {
extend: 'Ext.data.Store',
model: 'AM.model.User',
autoLoad: true,
proxy: {
type: 'ajax',
api: {
read: 'data/users.json',
update: 'data/updateUsers.json'
},
reader: {
type: 'json',
root: 'users',
successProperty: 'success'
}
}
});
hope that help

Related

FullCalendar - Vertical timeline, horizontal days

I would like to know, if there is any way to create a calendar with FullCalendar in such format:
I formed resusers in the form of dates. But I see events only in one day. It is possible to correct the events. But maybe there is a way to display all the days in this format.
Thank you in advance!
Temporarily, I solved the problem this way:
<div class="panel-body">
<div id="calendar"></div>
</div>
#section Styles {
<link href="~/lib/fullcalendar/dist/fullcalendar.min.css" rel="stylesheet" />
<link href="~/lib/fullcalendar-scheduler/dist/scheduler.min.css" rel="stylesheet" />
}
#section Scripts {
<script src="~/lib/moment/moment.js"></script>
<script src="~/lib/fullcalendar/dist/fullcalendar.min.js"></script>
<script src="~/lib/fullcalendar/dist/locale/ru.js"></script>
<script src="~/lib/fullcalendar-scheduler/dist/scheduler.min.js"></script>
<script>
$(function () {
$('#calendar').fullCalendar({
defaultView: 'timelineDay',
slotDuration: '00:30',
slotWidth: 5,
height: 'auto',
eventOverlap: false,
nowIndicator: true,
businessHours: true,
defaultDate: "#DateTime.Now.ToString("yyyy-MM")-01",
titleFormat: 'MMMM YYYY',
header: {
left: 'myPrevButton,myNextButton',
center: 'title',
right: ''
},
customButtons: {
myNextButton: {
//text: 'Next',
icon: 'right-single-arrow',
click: function () {
$('#calendar').fullCalendar('incrementDate', {
months: 1,
});
$('#calendar').fullCalendar('refetchResources');
}
},
myPrevButton: {
//text: 'Prev',
icon: 'left-single-arrow',
click: function () {
$('#calendar').fullCalendar('incrementDate', {
months: -1,
});
$('#calendar').fullCalendar('refetchResources');
}
}
},
events: "/api/Sheduling/eventpersonal/#Model.Id",
refetchResourcesOnNavigate: true,
resources: '/api/Sheduling/1'
});
});
</script>
}
This solution works for me. But it requires superfluous operations.
This solution works for me. But it requires superfluous operations. I receive a schedule for one employee in the form of:
Resources:
[{"id":1,"title":"1/8"},{"id":2,"title":"2/8"},{"id":3,"title":"3/8"},{"id":4,"title":"4/8"},{"id":5,"title":"5/8"},{"id":6,"title":"6/8"}, ....
Events (where all start in the end date is the 1st day of the month, and the resourceId is the date of the month):
[{"color":"#006633","id":1,"resourceId":1,"start":"2018-08-01T10:05:00","end":"2018-08-01T10:09:50"},{"color":"#006633","id":1,"resourceId":1,"start":"2018-08-01T10:35:00","end":"2018-08-01T10:39:50"},{"color":"#006633","id":1,"resourceId":1,"start":"2018-08-01T11:05:00","end":"2018-08-01T11:09:50"},{"color":"#006633","id":1,"resourceId":1,"start":"2018-08-01T11:35:00","end":"2018-08-01T11:39:50"},{"color":"#006633","id":1,"resourceId":1,"start":"2018-08-01T12:05:00","end":"2018-08-01T12:09:50"},{"color":"#006633","id":1,"resourceId":1,"start":"2018-08-01T12:35:00","end":"2018-08-01T12:39:50"},{"color":"#006633","id":1,"resourceId":1,"start":"2018-08-01T13:05:00","end":"2018-08-01T13:09:50"},{"color":"#006633","id":1,"resourceId":1,"start":"2018-08-01T13:35:00","end":"2018-08-01T13:39:50"},{"color":"#006633","id":1,"resourceId":1,"start":"2018-08-01T14:05:00","end":"2018-08-01T14:09:50"},{"color":"#006633","id":1,"resourceId":1,"start":"2018-08-01T14:35:00","end":"2018-08-01T14:39:50"}, ....

Bootstrap Table using ajax not sorting or searching

I am using a simple bootstrap Table with data loading from ajax. I assume I am not using the data correctly in loading it into the columns and that is what is breaking it from sorting and searching. Can someone please help. This is what my code is-
`
<table id="table"></table>
<script>
$(document).ready(function () {
$.ajax({
url: 'http://dev.cehtp.org/api/water/get/3301477',
dataType: 'json',
success: function(jsnData) {
$('#table').bootstrapTable({
data: jsnData.rows, //this seems to be my problem area
columns: [{
field: 'id',
title: 'Id',
sortable: true,
searchable:true
}, {
field: 'name',
title: 'name',
sortable: true,
searchable:true
}]
});
}
});
});
</script>
`

Ajax Not returning Data to Action ASP.net MVC

I am new to MVC and facing a problem with accessing data via ajax in action of my ASP.NET Application.
Here is my Ajax Code:
$('.testBtn').click(function() {
$.ajax({
type: 'GET',
data: { id: 10 },
url="#Url.Action("GetData", "Consultation")",
success:function()
{
}
});
});
And here is my action inside the controller:
public ActionResult GetData(int id)
{
string x=id.ToStrring();
return null;
}
For testing I am just passing a static integer and getting its value inside my action.
On clicking the button I am getting the following error:
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult GetData(Int32)' in 'careshade_mvc.Controllers.ConsultationController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Here is working code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.testBtn').click(function () {
$.ajax(
{
url: 'Consultation/GetData',
type: "POST",
data: { id: 10 },
success: function (result) {
}
});
});
});
</script>
</head>
<body>
<input type="button" class="testBtn" value="ClickHere" name="button">
</body>
</html>
Try this:
$(document).ready(function() {
var id = 10;
$('.testBtn').click(function () {
$.ajax(
{
url: 'Consultation/GetData/' + id,//instead data: { id: 10 },
type: "GET",
success: function (result) {
}
});
});
});
You need to use a colon(:) character after url not the equals(=) sign.
Simply change:
url="#Url.Action("GetData", "Consultation")",
To this:
url:"#Url.Action("GetData", "Consultation")",
This was the only change I had to make to make the call work.Hope it helps you!

Can i use angular kendo grid in my asp.net project

I am currently using asp.net 4 with bootstrap 3 in my project, Here i used bootstap typeahead for autocomplete textbox so i want that once user select data from autocomplete list so that time it should do ajax call and angular kendo ajax call and should bind returned data in success event.
Below is my code:
updater: function (item) {
$('[id*=hdnHomeSearch]').val(map[item]);
populateSearchItem();
return item;
}
This is my typoahead method where i am containing textbox autocomplete selected data by user.
and in populateSearchItem method i want to call angularjs kendo grid which is below:
<script src="../scripts/jquery-1.11.3.js" type="text/javascript"></script>
<script src="../Content/dist/js/bootstrap.min.js" type="text/javascript"></script>
<script src="../scripts/angularjs.min.js" type="text/javascript"></script>
<script src="../Content/dist/js/kendo.all.min.js" type="text/javascript"></script>
<script src="../scripts/typoAhead.js" type="text/javascript"></script>
<div ng-app="app" ng-controller="MyCtrl">
<div kendo-grid k-options="gridOptions" k-rebind="gridOptions" k-pageable='{ "pageSize": 2, "refresh": true, "pageSizes": true }'></div>
</div>
<script type="text/javascript">
angular.module("app", ["kendo.directives"]).controller("MyCtrl", function ($scope, $http) {
$scope.gridOptions = {
columns: [{ field: "EmployeeKey" }, { field: "FirstName"}],
dataSource: {
transport: {
read: {
type: "POST",
url: '<%=ResolveUrl("Search.aspx/GetData1") %>',
dataType: "json",
contentType: "application/json"
},
parameterMap: function (options, operation) {
return JSON.stringify(options);
}
},
pageSize: 5,
schema: {
data: "Data",
errors: "Errors",
total: "Total",
model: {
id: "EmployeeKey",
fields: {
EmployeeKey: { editable: false, defaultValue: 0 },
FirstName: { type: "string", validation: { required: true} }
}
}
}
}
}
});
</script>
but after using this getting error text in console that is angular modulerr.
so this script method i want to use inside populateSearchItem method.
All suggestions are welcome.

Kendo Grid not binding to JSON result from ASMX Web Service

I have a problem binding Kendo GRID to ASP.NET asmx web service.
Following is HTML Code
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="styles/kendo.common.min.css" />
<link rel="stylesheet" href="styles/kendo.default.min.css" />
<link rel="stylesheet" href="styles/kendo.dataviz.min.css" />
<link rel="stylesheet" href="styles/kendo.dataviz.default.min.css" />
<link href="styles/kendo.common-bootstrap.min.css" rel="stylesheet" />
<link href="styles/kendo.bootstrap.min.css" rel="stylesheet" />
<link href="../BOOTSTRAP/bootstrap.min.css" rel="stylesheet" />
<script src="../Scripts/jquery-2.0.3.min.js"></script>
<script src="js/kendo.all.min.js"></script>
<script src="../BOOTSTRAP/bootstrap.min.js"></script>
</head>
<body>
<div id="example">
<div id="grid" class="table table-bordered"></div>
<script>
$(document).ready(function () {
$("#grid").kendoGrid({
columns: [
{ field: "srno", title: "SRNO" },
{ field: "party", title: "PARTY" }
],
dataSource: new kendo.data.DataSource({
transport: {
read: {
url: "../Service/DatabaseHandling.asmx/GetPurchaseJangad_JSON",
dataType: "json",
contentType: "application/json; charset=utf-8"
}
}
}),
schema: {
data: "d"
},
sortable: true
});
});
</script>
</div>
</body>
</html>
JSON returned from service is looking ok as below.
{"d":"[{\"srno\":17,\"party\":\"PARESH\",\"dt\":\"11/5/2015\",\"weight\":15000.0,\"timestamp\":\"2015-05-11T20:19:55.093\"},{\"srno\":18,\"party\":\"SIM\",\"dt\":\"11/5/2015\",\"weight\":11000.0,\"timestamp\":\"2015-05-11T20:21:44.177\"}]"}
Still nothing is visible on GRID.
And no error in browser console.
I think the issue is with the JSON data only.
Modified JSON given below, replaced \" with " and removed the quote just before and after the square brackets
{"d":[{"srno":17,"party":"PARESH","dt":"11/5/2015","weight":15000.0,"timestamp":"2015-05-11T20:19:55.093"},{"srno":18,"party":"SIM","dt":"11/5/2015","weight":11000.0,"timestamp":"2015-05-11T20:21:44.177"}]}
Please find the fiddle here after cleaning up the json
I changed the jQuery code to following.
$(document).ready(function () {
var data;
var webMethod = "../Service/DatabaseHandling.asmx/GetPurchaseJangad_JSON";
var parameters = "{}";
$.ajax({
contentType: "application/json; charset=utf-8",
url: webMethod,
data: parameters,
dataType: "json",
success: function (response) {
data = $.parseJSON(response.d);
console.log(data);
$("#grid").kendoGrid({
columns: [
{ field: "srno", title: "SRNO" },
{ field: "party", title: "PARTY" },
{ field: "dt", title: "DATE" },
{ field: "weight", title: "WEIGHT" }
],
dataSource: {
transport: {
read: function (options) {
options.success(data);
}
},
schema: {
}
}
});
}
});
});
What I did, is called that service via jQuery ajax. Got the data containing backslash and quotes. Then as in code, used $.parseJSON to get the required JSON format. Then passed that data to Kendo GRID after success. And thats how its working for me.
But still I am looking for a way to do this on server side, if possible.
Thanks

Resources