kendo datepicker month template with min and max value - kendo-ui

i have set a min and a max value on a kendo datepicker. Now the dates that are not in range are not shown, but i want to see the dates, but grayed out.
I was looking at the monthtemplate property, but i can't get my template right. I have following code, but it gives a template error.
#(Html.Kendo().DatePickerFor(m => m.PurchaseDate)
.Value(Model.PurchaseDate)
.Max(DateTime.Today)
.MonthTemplate("# if data.date < '"+DateTime.Today+"') { #" +
"<div class='inarray'>#= data.value #</div>" +
"# } else { #" +
"<div class='outofarray'>#= data.value #</div>" +
"# } #")
.Events(ev => ev.Change("setMinExpiryDate"))
)
thanks for your help

Try this,
#(Html.Kendo().DatePickerFor(m => m.PurchaseDate)
.Value(DateTime.Now)
.Max(DateTime.Today)
.MonthTemplate("# if (data.date < '" + DateTime.Today + "') { #" +
"<div class='inarray'>#= data.value #</div>" +
"# } else { #" +
"<div class='outofarray'>#= data.value #</div>" +
"# } #")
.Events(e => e.Change("setMinExpiryDate"))

it wasn't even that difficult, there is also an empty template you can set. And that did the trick for me.
#(Html.Kendo().DatePickerFor(m => m.PurchaseDate)
.Value(Model.PurchaseDate)
.Max(DateTime.Today)
.MonthTemplate(m=>m.Empty("<div class='outofarray'>#= data.value #</div>"))
.Events(ev => ev.Change("setMinExpiryDate")))

Related

Ajax function is never called inside dynamically generated buttons

This loop generate buttons in my HTML inside an AJAX function.
for( var i = 0; i<len; i++){
var d = new Date(response[i]['date']);
dformat = [d.getDate() + '/' +
(d.getMonth()+1) + '/' +
d.getFullYear() + ' ' +
d.getHours() + ':' +
d.getMinutes()];
console.log(response[i])
var bons = "<tbody>" +
"<th>" + response[i]['id'] + "</th>" +
"<td>" + dformat + "</td>" +
"<td>" + response[i]['poids'] + "</td>" +
"<td>" + response[i]['origine'] + "</td>" +
"<td>" + response[i]['type'] + "</td>" +
"<td>" + response[i]['famille'] + "</td>"
if(response[i]['localisation'] != "Expédié"){
bons = bons + "<td> <input class='evacuate' id='" + response[i]['id'] + "' type='button'" + "value='Evacuer'> </td>"
}else{
bons = bons + "<td>" + response[i]['localisation'] + "</td>"
}
bons = bons + "</tr>" +
"</tbody>"
$("#index").append(
bons
);
}
Then I have another AJAX function which makes every buttons previously generated clickable like :
$(".evacuate").on('click', function(){
console.log("test des boutons")
});
Problem is, the console.log isn't displayed, as if the function is never called. What am I doing wrong here ?
Try this:
$(document).on('click','.evacuate', function(){
console.log("test des boutons")
});
You should define the click event on elements that already exist on the page. So for your situation, select the parent element and then add click event. For example if the element with evacuate class is inside an element with someclass class, this will work:
$(".someclass").on('click', '.evacuate', function(){
console.log("test des boutons")
});
According to your code, you can use tbody tag as parent:
$("tbody").on('click', '.evacuate', function(){
console.log("test des boutons")
});
I don't really understand how this works but thanks to the answers given above I managed to display my console.log.
$(document.getElementsByName).on('click', '.evacuate', function(){
console.log("Test des boutons")
});

NVD3: Add the 'total' value to stackedAreaChart's interactiveGuideline

Is there a simple way to include the TOTAL value in the stackedAreaChart's interactiveGuideline tooltip? It'd be great if I could display total users using this awesome tooltip as well.
If not, what's the cleanest alternative?
You can use interactiveGuideline.tooltip.contentGenerator
https://github.com/novus/nvd3/blob/master/src/tooltip.js#L316
e.g.
chart.multiChart.interactiveLayer.tooltip.contentGenerator(function(d) {
var header = d.value;
var headerhtml =
"<thead><tr><td colspan='3'><strong class='x-value'>" +
header +
"</strong></td></tr></thead>";
var bodyhtml = "<tbody>";
var series = d.series;
series.forEach(function(c) {
var value = (c.value || 0).toFixed(2);
if (
c.key === keyForActualGreaterThanPredicted ||
c.key === keyForActualLessThanPredicted
) {
var diff = Math.abs(c.data.y0 - c.data.y1);
if (diff === 0) {
value = "-";
} else {
value = diff.toFixed(2);
}
}
bodyhtml =
bodyhtml +
"<tr><td class='legend-color-guide'><div style='background-color: " +
c.color +
";'></div></td><td class='key'>" +
c.key +
"</td><td class='value'>" +
value +
"</td></tr>";
});
bodyhtml = bodyhtml + "</tbody>";
return "<table>" + headerhtml + "" + bodyhtml + "</table>";
});

required on selectpicker based on div

I am learner in javaScript
How to write required on selectpicker based on
var typeSelectBox = "<select id='depprojsDevice' class='selectpicker'>";
typeSelectBox += "<option value=''> -- SELECT --</option>";
if (arr) {
for (var i in arr) {
typeSelectBox += "<option value='" + arr[i][2] + "'>" + arr[i][0] + " " + arr[i][1] + "</option>";
}
}
typeSelectBox + "</select>";
$('#depprojsDevice_Div').html(typeSelectBox);
$("div#depprojsDevice_Div select[id = 'depprojsDevice']").attr('required','required');
$(function(){
$("#depprojsDevice").prop('required',true);
});
Try This Code

Kendo Autocomplete datavalue field is not coming

Hi i am using kendo ui autocomplete but i am not getting the Value field in the server wrapper code. any help is greatly appriciated. if any alternative is there for this issue please suggest.
var comboBox = htmlHelper.Kendo().AutoComplete()
.Name(tag + propertyName)
.Value((propertyValue ?? ""))
.DataTextField("Text")
.HtmlAttributes(new { value = propertyValue })
.DataSource(source =>
{
source.Read(read =>
{
read.Action("Search", controller); //Set the Action and Controller name
})
.ServerFiltering(true);
}).HighlightFirst(true).HtmlAttributes(htmlAttributes).Enable(!enabled.HasValue ? true : enabled.Value);
//.Events(e => e.Change("function(e){ if(ComboOnChange(e)){" + onChange + "(e);} }")
//.DataBound("function(e){ " + onBind + " }")).ToHtmlString();
if(!String.IsNullOrEmpty( onChange))
{
comboBox.Events(e => e.Change("function(e){ if(ComboOnChange(e)){" + onChange + "(e);} }"));
}
if (!String.IsNullOrEmpty(onBind))
{
comboBox.Events(e => e.DataBound("function(e){ " + onBind + " }"));
}
var comboBoxData = comboBox.ToHtmlString();
comboBoxData = comboBoxData.Replace("name=\"" + tag + propertyName + "\"", "name=\"" + propertyNameId + "\"");
comboBoxData = comboBoxData.Replace("name=\"" + tag + propertyName + "-input\"", "name=\"" + propertyNameId + "\"");
This may be outdated, have you tried something like autocomplete[0].value?

LINQ-2-SQL How-To "Reuse" sub selections

Let's assume:
I have an EVENT table
I have a CLIENT table
And ADDRESS table have some column: UnitNo, StreetNo, StreetName, City, AddressType etc
A CLIENT has many EVENTs and CLIENT can have many ADDRESSes also
So if I want to query list of events with client HOME address street name, I just go
var qry = db.Events
.Select(evt => new {
EventAddress =
evt.Client
.Addresses
.FirstOrDefault(a => a.AddressType.Equals("HOME")).StreetName
});
However, if I want to get the full address I will need to concatenate sereval address fields. At the moment I am trying something like
var qry = db.Events
.Select(evt => new {
EventAddress =
evt.Client
.Addresses
.FirstOrDefault(a => a.AddressType.Equals("HOME")).StreetNo + " " +
evt.Client
.Addresses
.FirstOrDefault(a => a.AddressType.Equals("HOME")).StreetName + " " +
evt.Client
.Addresses
.FirstOrDefault(a => a.AddressType.Equals("HOME")).City
});
It doesn't work and looks ugly too
Is there a better way to make the
evt.Client.Addresses.FirstOrDefault(a => a.AddressType.Equals("HOME")) "reusable" so I can just go
var qry =
db.Events
.Select(evt => new {
EventAddress =
STUFF.StreetNo + " " + STUFF.StreetName + " " + STUFF.City
});
Many thanks in advance!
Hugh
UPDATE:
Thanks Ilian for the answer, it works well. And based on that I have created the extension version of the answer
var qry =
db.Events
.Select(evt => new {
EventAddress =
db.Addresses.Select(a => new
{
ClientId = a.ClientId,
AddressType = a.AddressType,
FullAddress = (a.addStreetNo ?? "") + (a.addStreetName ?? "")
})
.FirstOrDefault(a => a.ClientId == e.Client.ClientId && a.AddressType.Equals("HOME"))
.FullAddress
});
Use the query syntax:
var qry =
from evt in db.Events
let firstAddress = evt.Client.Addresses.FirstOrDefault(a => a.AddressType.Equals("HOME"))
where firstAddress != null
select new
{
EventAddress = firstAddress.StreetNo + " " +
firstAddress.StreetName + " " +
firstAddress.City
}

Resources