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?
Related
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>";
});
in flask-admin model view I want to filter a dropdown menu in the edit/create view of field that is a relationship, based on values entered in the previous field.
In the specific case, I would like to see only the ones in the "posto" that are displayed in another table belonging to the selected 'categoria'
class Tag(db.Model):
__tablename__ = 'tags'
nr_TAG = db.Column(db.Integer, primary_key=True)
categoria_id = db.Column(db.Integer, db.ForeignKey('categorie.id'), nullable=False)
categoria = db.relationship('Categoria', backref='tags')
posto_id = db.Column(db.Integer, db.ForeignKey('stalli.id'), nullable=False)
posto = db.relationship('Stallo', backref='tags')
cognome = db.Column(db.String(30), nullable=False)
nome = db.Column(db.String(30))
auto = db.Column(db.String(20))
targa = db.Column(db.String(10))
recapito = db.Column(db.String(80))
stato = db.Column(db.Integer)
posto_occ = db.Column(db.Integer)
orario = db.Column(db.Integer)
fuoriposto = db.Column(db.String(10))
parcheggio = db.Column(db.String(40))
class TagsAdmin(sqla.ModelView):
can_edit = True
can_create = True
column_list = ['nr_TAG', 'categoria', 'posto', 'cognome', 'targa',
'stato', 'orario', 'fuoriposto', 'parcheggio']
can_view_details = True
details_modal = True
form_columns = ['nr_TAG', 'categoria', 'posto', 'cognome', 'nome', 'auto', 'targa', 'recapito']
Any idea?
Thanks
I came up with following solution, maybe it's not perfect but it does the job:
master.html
function populateSelectField(to_populate, options, select) {
$('#s2id_' + to_populate + ' > a > span').text('');
var el = $('select[name$="' + to_populate + '"]');
el.children().remove();
option = '<option value=""></option>';
el.append($(option));
options.forEach(function(row) {
var option_id = row.id,
option_title = row.title;
if (select && option_id == select) {
option = '<option value="' + option_id + '" selected>' + option_title + '</option>';
$('#s2id_' + to_populate + ' > a > span').text(option_title);
} else {
option = '<option value="' + option_id + '">' + option_title + '</option>';
}
el.append($(option));
});
}
function getOptions(el, to_populate, url, select) {
var item_id = el.val(),
url = window.location.origin + url + item_id + '/';
$.get(url).done(function(options) {
populateSelectField(to_populate, options, select);
}).fail(function(err) {
console.error(err.message);
return false;
});
}
function selectFieldManipulation(from_populate, to_populate, url) {
var main_select = $('select[name$="' + from_populate + '"]'),
to_populate_el = $('select[name$="' + to_populate + '"]');
getOptions(main_select, to_populate, url, to_populate_el.val());
main_select.change(function(e) {
getOptions(main_select, to_populate, url, null);
});
}
create.html / edit.html
$(document).ready(function() {
selectFieldManipulation('from_populate', 'to_populate', '/api/route_to_view/');
});
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")))
Given this:
public static List<DoctorFullName> GetListDoctorsNames()
{
using (var db = new WaitListDataContext())
{
return db.Doctors.Select(c => new DoctorFullName()
{
FullName = c.FirstName + " " + c.LastName,
DoctorId = c.DoctorId
}).ToList();
}
}
How do can I return the list sorted by FirstName?
public static List<DoctorFullName> GetListDoctorsNames()
{
using (var db = new WaitListDataContext())
{
return db.Doctors.OrderBy(doc => doc.FirstName).Select(c => new DoctorFullName()
{
FullName = c.FirstName + " " + c.LastName,
DoctorId = c.DoctorId
}).ToList();
}
}
Just add an .OrderBy() clause. You can sort by only the FirstName before your .Select():
return db.Doctors
.OrderBy(c => c.FirstName)
.Select(c => new DoctorFullName()
{
FullName = c.FirstName + " " + c.LastName,
DoctorId = c.DoctorId
}).ToList();
Or you can sort it after your .Select(), since your new field begins with the FirstName value anyway:
return db.Doctors.Select(c => new DoctorFullName()
{
FullName = c.FirstName + " " + c.LastName,
DoctorId = c.DoctorId
})
.OrderBy(c => c.FullName)
.ToList();
The IEnumerable<T> interface provides a lot of methods for manipulating a collection and returning the modified collection, so they can be chained together in lots of different ways.
You should be able to do an ordering:
public static List<DoctorFullName> GetListDoctorsNames()
{
using (var db = new WaitListDataContext())
{
return db.Doctors
.OrderBy(d => d.FirstName)
.Select(c => new DoctorFullName()
{
FullName = c.FirstName + " " + c.LastName,
DoctorId = c.DoctorId
})
.ToList();
}
}
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
}