Kendo Ui web Listview - kendo-ui

I am using Listview of kendo ui. I have no server wrapper class I am using the free web version.
My controller code is given below:
public ActionResult Index()
{
return View();
}
public ActionResult GetCandidateSearch()
{
IhrmsEntities Entity = new IhrmsEntities();
List<VW_CANDBASICSEARCH> lstCandidateSearch = Entity.VW_CANDBASICSEARCH.Take(50).ToList();
return Json(lstCandidateSearch,JsonRequestBehavior.AllowGet);
}
My index.cshtml
<div>
#Html.Partial("~/Views/Home/PvCandidateBasicSearch.cshtml")
</div>
My PvCandidateBasicSearch.cshtml
<div class="gridHolder" style="width: 100%">
<div id="listCandidateView" class="itemDisplay"></div>
<div id="pager"></div>
</div>
<script type="text/x-kendo-tmpl" id="template">
<div class="itemDisplay">
<div class="text-label">${CAND_NAME} </div>
<div class="text-label">${CAND_LOCATION} </div>
<div class="text-label">${CAND_MOBILE} </div>
<div class="text-label">${CAND_PRE_EMAIL} </div>
<div class="text-label">${CAND_SKILL} </div>
<div class="text-label">${CAND_CITY} </div>
<a href="/Home/EditCandidate?id=${CAND_ID}" >Edit</a>
<a href="/Home/DeleteCandidate?id=${CAND_ID}" >Delete</a>
</div>
</script>
<style type="text/css">
.text-label {
font-size: large;
}
.itemDisplay {
margin: auto;
padding: 6px 8px;
width:auto;
min-width:200px;
height: auto;
min-height:100px;
border: 1px solid #999999;
-webkit-border-radius: 6px;
border-radius: 6px;
font-weight: normal;
background: #deefff;
}
.gridHolder{width: 100%; height:auto; min-height:300px; margin:auto;}
</style>
My javascript code in layout.cshtml is given below
<script type="text/javascript">
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: '/Home/GetCandidateSearch',
type: "GET",
dataType: "json"
}
},
pageSize: 15
});
$("#pager").kendoPager({
dataSource: dataSource
});
$("#btnSearch").click(function () {
LoadListView();
});
function LoadListView() {
$("#listCandidateView").kendoListView({
dataSource: dataSource,
pageable: true,
template: kendo.template($("#template").html())
});
}
</script>
when I first click search button it is perfectly going to the GetCandidateSearch action method and showing result.But when I second time clicking search button it is not going the action method. Plz help me.

You're misunderstanding the the datasource concept.
The datasource is an object holds the data gathered from request. On the second click you just re-binding that datasource to the ListView...
Basically, you need to bind the list view to the datasource on page load, then "OnClick", do datasource.read()
try this:
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: '/Home/GetCandidateSearch',
type: "GET",
dataType: "json"
}
},
pageSize: 15
});
$(document).ready(function() {
$("#listCandidateView").kendoListView({
dataSource: dataSource,
pageable: true,
template: kendo.template($("#template").html())
});
});
$("#btnSearch").click(function () {
$("#listCandidateView").datasource.read();
});
Not saying that the exact code will work, but it should give you an idea of the approach.

Related

Having problem in Dynamic CSS in Vue-laravel

Here's the template where my button and contactList1 reside:-
<template>
<div class="chat-app">
<button v-on:click="displayList1()">Contacts List 1</button> //Button
<Conversation :contact="selectedContact" :messages="messages" #new="saveNewMessage" v-bind:class="{conversation:conversation}" />
<ContactsList :contacts="contacts" #selected="startConversationWith" v-bind:class="{contactsList1:contactsList1}"/> //contactsList
</div>
</template>
The object is default set to false
data() {
return {
contactsList1: {
default: false,
},
},
Method:-
displayList1()
{
this.contactsList1 = false;
},
Style:-
<style lang="scss" scoped>
.chat-app {
display: flex;
}
.contactsList1 {
background-color: black;
}
</style>
Even after the object being false the css is being applied, can anyone tell me what's wrong. I am just a beginner, Please help.
Your data function is returning the object contactsList1 and the full path to check the data type is this.contactsList1.default
You should also name your variables differently.
So here is a basic example on how to bind a Boolean datatype to your component class:
new Vue({
el: "#app",
data() {
return {
firstClass: {
status: false
}
}
},
methods: {
changeColour() {
this.firstClass.status = true
}
}
})
.styleFirstClass {
background: red
}
.itemBox {
padding:30px;
margin:30px;
border: 1px solid #444;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<button #click="changeColour()">Click to bind class</button>
<div class="itemBox" :class="{styleFirstClass: firstClass.status}">
This is some text
</div>
</div>

Video clicks count laravel

I am trying to count the number of clicks on my video using Laravel. I followed this tutorial I found on Google: http://cameronscott.co/posts/tracking-page-clicks-in-laravel but nothing is working. I clicked on the video and it didn't increment in the database. Here is my code.
Route:
Route::get('video/{id}/click','ClickController#clickvideo');
Controller:
class ClickController extends Controller
{
public function clickvideo($id){
$po=User::findorfail($id);
$po->increment('clicks');
$po->update();
}
Views:
<a href="{{url('video/{$proo->id}/click')}}" class="js-click-video" style="border:none; background:none;">
<video class="video1" id="cb" preload="auto" data-post-id="{$proo->id}" style=" overflow: hidden; width: 30vh; object-fit: cover; float:left; clear:both;
height: auto; padding-left:2%; margin-top:0px; border:2px solid white; cursor:pointer; "><source src="{{$proo->intro_video}}#t=13" playsinline alt="Video Unavailable" id="" ></source>
</a>
JavaScript:
$('.js-click-video').click(function(e){
e.preventDefault();
var post=$(this).closest('.video1');
var postId=post.attr('data-post-id');
registerPostClick(postid);
});
function registerPostClick(postid){
$.ajaxSetup({
headers:{
'X-CSRF-TOKEN' : $('meta[name="_token"]').attr('content')
}
})
$.ajax({
type: 'post',
dataType: 'JSON',
url: '/video/' + postId + '/click',
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(JSON.stringify(xhr.responseText));
}
});
}
You are missing a mustache in your variable name here:
data-post-id="{$proo->id}"
Should be
data-post-id="{{$proo->id}}"
This should also be:
*{{url('video/{$proo->id}/click')}}*
{{url('video/' . $proo->id .'/click')}}
Also, this is not necessary
$po->update();

Passing value to a kendoWindow template

Given the below template and function, how can I pass the function argument contentText to display in the template #password-validation at the placeholder ###?
Template
<script id="password-validation" type="text/x-kendo-template">
<p style="font-size: 12px; padding: 10px">
###
</p>
<div style="text-align: right">
<button class="password-ok k-button">OK</button>
</div>
</script>
Function
function PasswordValidation(contentText) {
var kendoWindow = $("<div />").kendoWindow({
actions: ["Close"],
title: "Password validation",
resizable: false,
modal: true
});
kendoWindow.data("kendoWindow")
.content($("#password-validation").html())
.center().open();
kendoWindow
.find(".password-ok")
.click(function () {
kendoWindow.data("kendoWindow").close();
})
.end()
}
here is solution:
<script id="password-validation" type="text/x-kendo-template">
<p style="font-size: 12px; padding: 10px">
#=data#
</p>
<div style="text-align: right">
<button class="password-ok k-button">OK</button>
</div>
</script>
and function:
function PasswordValidation(contentText) {
var kendoWindow = $("<div />").kendoWindow({
actions: ["Close"],
title: "Password validation",
resizable: false,
modal: true
});
var template = kendo.template($("#password-validation").html());
kendoWindow.data("kendoWindow")
.content(template(contentText))
.center().open();
kendoWindow
.find(".password-ok")
.click(function () {
kendoWindow.data("kendoWindow").close();
})
.end()
}

Getting uploaded files count as zero while calling the function in controller through Json in mvc4

I created multiple file uploader dynamically using javascript within the div FileUploadContainer.while i put btnSubmit outside the form tag i get Request.Files.Count as zero.I need to call the PopUp() through Json .If i put btnSubmit inside the form tag
it does not call the Save() on javascript and will call PopUp() method on form submit.
I need to call the PopUp() through Json and need to get the Request.Files.Count .Pls help.
#using (Html.BeginForm("PopUp", "EnergyCatagory", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div id="FixedHeightContainer">
<div id="FileUploadContainer">
</div>
<input type="button" id="btnAddAttachment" name="btnAddAttachment" class="ZWidgetTitle"
value="Add More Attachments" onclick="AddFileUpload()" />
</div>
<div id="NewAttachment">
<div style="background-color: #DADADA;">
<center>
<label style="font-family: Verdana; font-size: 13px; font-weight: bold; color: black;
height: 30px; width: 100%; padding-top: 20px;" id="lblMessage">
</label>
</center>
</div>
</div>
<div class="horizSep">
</div>
<div id="buttons">
</div>
} <button id="btnSubmit" class="buttons" onclick="Save()">
Attach</button>
function Save()
{$.ajax({
url: '/EnergyCatagory/PopUp',
type: 'POST',
contentType: 'application/json;',
dataType: 'json',
success: function (result) {
alert("success");
}
});
}controller-----
public ActionResult PopUp()
{
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFileBase PostedFile = Request.Files[i];
if (PostedFile.ContentLength > 0)
{
string FileName = System.IO.Path.GetFileName(PostedFile.FileName);
var path1 = Path.Combine(Server.MapPath("~/Files/"), FileName);
//PostedFile.SaveAs(Server.MapPath("Files\\") + FileName);
PostedFile.SaveAs(path1);
return Json(
new
{
CustomMessage = "My message",
});
}
}
If the form is getting submitted and don't calling the function onclick is because the input type is a button, you can change it to html a link tag.
also calling a inline javascript (onclick) is not good practice, i notice you use jquery so why don't do it with jquery?
function Save(){
$.ajax({
url: '/EnergyCatagory/PopUp',
type: 'POST',
contentType: 'application/json;',
dataType: 'json',
success: function (result) {
alert("success");
}
});
$("#btnSubmit").click(function(){
Save();
});
#using (Html.BeginForm("PopUp", "EnergyCatagory", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div id="FixedHeightContainer">
<div id="FileUploadContainer">
</div>
<input type="button" id="btnAddAttachment" name="btnAddAttachment" class="ZWidgetTitle"
value="Add More Attachments" onclick="AddFileUpload()" />
</div>
<div id="NewAttachment">
<div style="background-color: #DADADA;">
<center>
<label style="font-family: Verdana; font-size: 13px; font-weight: bold; color: black;
height: 30px; width: 100%; padding-top: 20px;" id="lblMessage">
</label>
</center>
</div>
</div>
<div class="horizSep">
</div>
<div id="buttons">
</div>
<a id="btnSubmit" class="buttons">Attach</a>
}
i think you are getting Request.Files.Count equals zero is because you don't have any input type file? do you?

MVC3 partial view for edit pop-up

I am writing a MVC3 project. Right now I have a table which has column with Data as actionLinks as:
<td style="color: Black; background-color: Bisque; text-align: center; width: 410px">
#Html.ActionLink(#item.LookUp_NameString, "EditPartial", "Capitation", new { id = item.CAPITATION_RATE_ID }, new { #class = "actionLink" })
</td>
EditPartial as the name suggests is a partial view, which I need to be opened as a pop-up menu so that user can edit the details of the object save it and we can come back to original page.
Thanks for the help!
You could use jQuery and jQueryUi to capture the click and open the rendered action in a dialog box.
<div id="popupWindow" style="display: none;" ></div>
<script type="text/javascript">
$(function() {
$("#popupWindow").dialog({
width: 600,
autoOpen: false
});
$('a.actionLink').click(function() {
var url = $(this).attr('href');
$('#popupWindow').load(url, function() {
$('#popupWindow').dialog('open');
});
return false;
});
});
</script>

Resources