I have following Kendo.mvc grid
#Html.HiddenFor(model => model.BarCode)
<div style="padding-left:10%;padding-top:2%">
#(Html.Kendo().Grid(Model.BarCodes)
.Name("grid")
.Columns(columns =>
{
columns.Bound(e => e.DocumentSetName)
.Width(100)
.Title("Reference No");
columns.Bound(e => e.ScannedDate)
.Title("Scanning Date")
.Width(100);
})
.Sortable()
.Pageable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(3)
//.Read(read => read.Action("SearchUnregisteredIncomings", "Correspondence").Data("getSearchCriteria"))
)
.ClientDetailTemplateId("template")
)
and this is the ajax call I have made
$.getJSON('#Url.Action("Search")', {ReferenceNumber:'123'
}, function (data, status) {
var grid = $("#grid").data("kendoGrid");
grid.dataSource.data(data);
grid.refresh();
$("#loading").stop().fadeOut('fast');
});
The grid variable is undefined.
The following is the names and sequence of .js files and scripts that are loaded in _Layout.cshtml file.
<script src="/Scripts/modernizr-2.6.2.js"></script>
<script src="/Scripts/kendo/jquery.min.js"></script>
<script src="/Scripts/spin.js"></script>
<script src="/Scripts/kendo/kendo.all.min.js"></script>
<script src="/Scripts/bootstrap-multiselect.js"></script>
<script src="/Scripts/kendo/kendo.aspnetmvc.min.js"></script>
<script src="/Scripts/chosen.jquery.min.js"></script>
And the below scripts loaded after #RenderBody() section but before </body> tag
<script src="/Scripts/jquery-1.10.2.js"></script>
<script src="/Scripts/jquery-1.8.2.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/respond.js"></script>
<script src="/Scripts/spcontext.js"></script>
<script src="/Content/vendors/jquery-1.9.1.js"></script>
<script src="/Content/vendors/modernizr-2.6.2-respond-1.1.0.min.js">/script>
<script src="/Content/vendors/jquery.uniform.min.js"></script>
<script src="/Content/vendors/chosen.jquery.min.js"></script>
<script src="/Content/vendors/bootstrap-datepicker.js"></script>
<script src="/Content/vendors/wysiwyg/wysihtml5-0.3.0.js"></script>
<script src="/Content/vendors/wysiwyg/bootstrap-wysihtml5.js"></script>
<script src="/Content/vendors/wizard/jquery.bootstrap.wizard.min.js"></script>
<script src="/Content/assets/treeview.js"></script>
<script src="/Content/assets/form-validation.js"></script>
<script>
$(function () {
$(".datepicker").datepicker();
$(".uniform_on").uniform();
$(".chzn-select").chosen();
$('.textarea').wysihtml5();
});
(function (window, undefined) {
var $ = window.jQuery;
var document = window.document;
$(document).ready(function () {
//some code here
});
})(window);
I think the problem is due to the sequence of .js files but can not figure it out.
Related
I cannot figure out how to use WebSocketSubjects in rxjs v6.x
Here's the working HTML/JS for v5.5.6. The commented out code is my attempt at getting it working in v6.x:
<html>
<head>
<!-- <script src="https://unpkg.com/#reactivex/rxjs#6.0.0/dist/global/rxjs.umd.js"></script> -->
<script src="https://unpkg.com/#reactivex/rxjs#5.5.6/dist/global/Rx.js"></script>
<script>
// const { WebSocketSubject } = rxjs.webSocket;
// const socket$ = WebSocketSubject.create('ws://localhost:8080');
const socket$ = Rx.Observable.webSocket('ws://localhost:8080');
socket$.subscribe(
(data) => console.log(data),
(err) => console.error(err),
() => console.warn('Completed!')
);
socket$.next(JSON.stringify({
event: 'events',
data: 'test',
}));
console.log('here')
</script>
</head>
<body></body>
</html>
I got it working with rxjs#6.1.0. As I suspected, I was just using the version 6 syntax wrong. See working example:
<html>
<head>
<script src="https://unpkg.com/#reactivex/rxjs#6.1.0/dist/global/rxjs.umd.js"></script>
<script>
const { WebSocketSubject } = rxjs.webSocket;
const socket$ = new WebSocketSubject('ws://localhost:8080');
socket$.subscribe(
(data) => console.log(data),
(err) => console.error(err),
() => console.warn('Completed!')
);
socket$.next({
event: 'events',
data: 'test',
});
console.log('here')
</script>
</head>
<body></body>
</html>
Here I wrote A code which fetches data from API http://fcctop100.herokuapp.com/api/fccusers/top/recent and displays on console for starter but I'm Getting Error Like "parsererror" "Error: jQuery21106393266040831804_1456914722748 was not called"
var App = React.createClass({
//setting up initial state
getInitialState:function(){
return{
data:[]
};
},
componentDidMount(){
this.getDataFromServer('http://fcctop100.herokuapp.com/api/fccusers/top/recent');
},
//showResult Method
showResult:function(response){
console.log(response);
this.setState({
data:response.results
});
},
//making ajax call to get data from server
getDataFromServer:function(URL){
$.ajax({
type:"GET",
dataType:"jsonp",
url:URL,
success: function(response) {
this.showResult(response);
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
render:function(){
return(
<div>
<Result />
</div>
);
}
});
var Result = React.createClass({
render:function(){
return(
<div>
<ul>
<ResultItem/>
</ul>
</div>
);
}
});
var ResultItem = React.createClass({
render:function(){
return(
<div>
<li>Hello This Is From ResultItem Component</li>
</div>
);
}
});
ReactDOM.render(
<App />,
document.querySelector("#app")
);
<!DOCTYPE html>
<head>
<meta charset="UTF-8" />
<title>React Tutorial</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<div id="app"></div>
<script src="demo.js" type="text/babel"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.2/marked.min.js"></script>
</body>
</html>
Your API returns JSON, you don't need use JSONP, just change dataType from jsonp to json
$.ajax({
type: "GET",
dataType: "json",
....
});
and in showResult set only response because response contains Array of Objects and does not have results property
this.setState({
data: response
});
Example
I need to disable resizing for only one column only in a kendo grid.
I have seen the columnresize event, but I do not understand how to use it in my grid example below.
I noted that there is a similar question
My grid-
#(Html.Kendo().Grid<CCCAdmin.ViewModels.AdminReportViewModel>().Name("AdminReportGrid")
.HtmlAttributes(new {#class = "table table-bordered"})
.Columns(columns =>
{
columns.Bound(l => l.Id).Width("11%").Title("Id");
columns.Bound(l => l.CustomerName).Width("30%");
}).Resizable(r => r.Columns(true))
.Excel(excel => excel
.FileName("Admin Report Export.xlsx")
.Filterable(true)
.ProxyURL(Url.Action("Excel_Export_Save", "AdminReport")))
.DataSource(dataSource => dataSource
.Ajax().Read(read => read.Action("AdminReport_Read", "AdminReport"))
.Destroy(update => update.Action("AdminReportDestroy", "AdminReport"))
.Sort(sort => sort.Add("CallCounting").Descending())
.PageSize(20)
.Model(model =>
{
model.Id(a => a.Id);
})
)
.Events(events =>
{
events.DataBound("dataBound");
events.ExcelExport("onExcelExport");
}
)
.ClientDetailTemplateId("CustomerInvoices")
.Sortable()
.Filterable()
)
There is no out of box feature in Kendo ASP.NET MVC but you can accomplish the task with Javascript. In following example, column Id will not be resized.
var grid = $("#GridName").data("kendoGrid");
grid.resizable.bind("start", function (e) {
if ($(e.currentTarget).data("th").data("field") == "Id") {
e.preventDefault();
setTimeout(function () {
grid.wrapper.removeClass("k-grid-column-resizing");
$(document.body).add(".k-grid th").css("cursor", "");
});
}
});
Demo
$(function(){
$("#grid").kendoGrid({
dataSource: {
data: [
{Id: "1", FirstName: "Amar",LastName: "X"},
{Id: "2", FirstName: "Akbar",LastName: "Y"},
{Id: "3", FirstName: "Anthony",LastName: "Z"}
]
},
resizable: true
});
var grid = $("#grid").data("kendoGrid");
grid.resizable.bind("start", function(e) {
if ($(e.currentTarget).data("th").data("field") == "Id") {
e.preventDefault();
setTimeout(function(){
grid.wrapper.removeClass("k-grid-column-resizing");
$(document.body).add(".k-grid th").css("cursor", "");
});
}
});
});
<head>
<title>Kendo UI Snippet</title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.common.min.css"/>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.rtl.min.css"/>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.silver.min.css"/>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.2.516/styles/kendo.mobile.all.min.css"/>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2018.2.516/js/kendo.all.min.js"></script>
</head>
<body>
<p>The <strong>Id</strong> column cannot be resized:</p>
<div id="grid"></div>
</body>
I have a telerik popped up window. It opens fine; however, I am having an issue closing the window. If I add an alert to the javascript, alert("#Window") or alert($(this).closest('#Window')), it will display [object Object]. However, alter("#Window").data("tWindow") or alert($(this).closest('#Window').data('tWindow')) will display null. I've removed the jquery and javascript reference from either the parent or the child page, and it did not make any difference. Any kind of help would be greatly appreciated. See sample code below
Here is the popup window:
#{Html.Telerik().Window()
.Name("Window")
.Title("Student Window")
.LoadContentFrom(Url.Action("AddReason", "Reason", new { id = reasonID }, Request.Url.Scheme))
.ClientEvents(events => events
.OnClose("ClosingWindow")
)
.Draggable(false)
.Scrollable(false)
.Width(800)
.Height(600)
.Modal(true)
.Visible(false)
//.Effects(fx => fx
// .Zoom()
// .Opacity())
.Render();
}
Here is the JavaScript:
<script src="#Url.Content("~/Scripts/jquery-1.4.4.js")" type="text/javascript">
</script>
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/spin.min.js")" type="text/javascript"></script>
function DoOpen(id) {
var url = '#Url.Action("AddReason","Reason")';
$.post(url, { id: id }, function (data) {
var window = $('#Window').data('tWindow').center();
window.content(data);
window.open();
});
}
//This javascript is in the main page
//I did an alert. alert($('#Window')) and
alert($('#Window').data('tWindow')) they both return null
function ClosingWindow() {
$('#Window').prop("checked", "checked");
$('#Window').data('tWindow').close();
window.location.href = window.location.href;
}
Here is the partial view :
#model Student.Models.Reason
#using Student.Example
#{
ViewBag.Title = "Add Reason";
Layout = "~/Views/Shared/_PartialReason.cshtml";
}
<script type="text/javascript">
function CloseWindow() {
// alert($("#Window").closest('.t-window').data('#tWindow'));
// $("#Window").data("tWindow").close();
$('#Window').prop("checked", "checked");
window.location.href = window.location.href;
}
</script>
#using (Html.BeginForm("AddReason", "Reason", FormMethod.Post))
{
#Html.ValidationSummary(true)
<fieldset>
<div class="editor-field">
#(Html.Telerik().Editor()
.Name("EncountersArchive")
.HtmlAttributes(new { style = "height:310px;", id = "AddAReason" })
.Encode(true)
.Tools(
tools => tools
.Clear()
.Bold().Italic().Underline().Strikethrough().Subscript().Superscript().Separator()
.FontName().FontSize()
.FontColor().BackColor().Separator()
.JustifyLeft().JustifyCenter().JustifyRight().JustifyFull().Separator()
.InsertUnorderedList().InsertOrderedList().Separator()
.Indent().Outdent().Separator()
))
</div>
<p style="text-align:center">
<input type="submit" value="Reason" id="AddReasonID" onclick="CloseWindow()"/>
</p>
</fieldset>
}
The OnClose event on the popup window was causing the issue. The onclose events should only be used if the user wished to do someonthing else after the window is closed. If the purpose is simply to close the window, the Telerik control is automatically handling it. In my case, I simply remove the onclose event, and it works like a charm.
I wrote this code in javascript to disply information in this page (Normal_Info.php),
but unfortunately it did not work. If anyone can help me I will be grateful
<html>
<head>
<script language="javascript">
function ajaxFunction()
{
return window.XMLHttpRequest ?
new window.XMLHttpRequest :
new ActiveXObject("Microsoft.XMLHTTP");
}
function Go_there()
{
var httpObj = ajaxFunction();
httpObj.open("GET","Normal_Info.php", true);
httpObj.send();
httpObj.onreadystatechange = ChangedState()
{
if (httpObj.readyState == 4 && httpObj.status == 200)
{
document.getElementById("result").innerHTML=httpObj.responseText;
}
}
}
</script>
</head>
<body>
<form id=ff>
<input type=button value=Hi OnClick=Go_there() />
</form>
<div id=result>
</div>
</body>
</html>
i suggest using jquery http://jquery.com/
<script src="jquery.js"></script>
<script language="javascript">
$('#ff').submit(function() {
$.ajax({
url: 'ajax/test.html',
success: function(data) {
$('#result').html(data);
// alert('Load was performed.');
}
});
});
</script>
no need to click event