I am using telerik asp.net mvc and I have a multi select:
@(Html.Kendo().MultiSelect()
.Name("msInvoicesAPV")
.Placeholder("Select invoices...")
.HtmlAttributes(new { required = "required", style = "width: 100%", validationmessage = "Select Invoice Numbers." })
.DataTextField("Number")
.DataValueField("Id")
.AutoBind(true)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetInvoicesByDateTimeRange", "Invoices")
.Data("getDateTimeRangeParameters");
})
.ServerFiltering(true);
})
)
now it is reading from a controller called Invoices and the action name is GetInvoicesByDateTimeRange
public ActionResult GetInvoicesByDateTimeRange(string start, string end)
{
var session = Session["AccessToken"];
try
{
DateTime startRange = Convert.ToDateTime(start);
DateTime endRange = Convert.ToDateTime(end);
string query = $"Type == \"ACCPAY\" AND Date >= DateTime({startRange.Year},{startRange.Month},{startRange.Day})" +
$" AND Date <= DateTime({endRange.Year},{endRange.Month},{endRange.Day})";
var invoices = _xeroCoreApi.Invoices.Where(query).Find();
return Json(invoices, JsonRequestBehavior.AllowGet);
}
catch (RenewTokenException e)
{
return RedirectToAction("Connect", "XeroOAuth");
}
}
as you can see, whenever it went to the catch part, I am redirecting it to another Action and controller
public ActionResult Connect()
{
var authorizeUrl = _authenticator.GetRequestTokenAuthorizeUrl(_user.Name);
return Redirect(authorizeUrl);
}
but I am getting errors of :
"Access to XMLHttpRequest at 'https://api.xero.com/oauth/Authorize?oauth_token=KNFURSOK8ZPTF1AMUKYQHT2E85FPTQ&scope=' (redirected from 'http://localhost:57141/Invoices/GetInvoicesByDateTimeRange?start=5%2F9%2F2019&end=11%2F19%2F2019') from origin 'http://localhost:57141' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request."
do I need to add "Access-Control-Allow-Origin:" as a header of the read property? if so how do I add it?
Hi,
I want to find out all the kendo dropdown lists on a page. I want to write a common function in a .js file where I can perform this feature. I am using the below version of Telerik
Version: 2019.2.619.545 (Kendo Web Extensions for ASP.NET MVC)
MVC version: 5.0
IDE: Visual Studio 2015
Browser : Chrome 76.0.3809.100, IE 11.0
.Net Framework: 4.6.2
Programming Language: C#
I tried to use the approach provided at https://stackoverflow.com/questions/21513056/finding-all-kendo-drop-downs-on-page but it's not working.
In my Kendo MVC grid, I have code as follows to place Edit and Destroy icons in a table cell:
columns.Command(command => { command.Edit().Text(" "); command.Destroy().Text(" "); }).Width(86);
I've attached a file that shows the result of this. As you can see, the container for the icons are much larger than they need to be and I have to devote almost 90 pixels to the column just to prevent the icons from wrapping. Is there a way I can make the icon containers smaller?
Hi,
I'm new to Telerik, and there's a lot about MVC that I'm still learning, so apologies in advance.
I have a Grid Control that I'm passing an object to (see code below). I want a detail page which is a little complex and beyond the scope of what a popup would handle, so a separate page is necessary.
I'm really struggling to get a "Select" button working to send route value out, something like /Person/Details/5
The grid itself is working as expected, however I can't seem to invoke a route or action based on the current selected row or invoke an action on the select button.
I've written a comment in the actual section I'm having a problem with.
Thanks
@(Html.Kendo().Grid(Model)
.Name(
"grid"
)
.Columns(columns =>
{
columns.Bound(p => p.person.Title).Width(100);
columns.Bound(p => p.person.Firstname);
columns.Bound(p => p.person.Firstname);
columns.Bound(p => p.person.Surname);
columns.Bound(p => p.person.ABN).Width(210);
columns.Bound(p => p.person.PracticeCode);
columns.Bound(p => p.currentform);
columns.Command(command => { command.Edit(); });
columns.Command(command => { command.Destroy(); });
columns.Command(command => { command.Select(); });
})
.Sortable()
.ToolBar(commands => commands.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.DataSource(dataSource => dataSource
.Server()
.Model(model => model.Id(p => p.person.pkey))
.Create(create => create.Action(
"Create"
,
"Person"
))
// I'm having trouble with this next line.
// All I want is the drkey to be a route value
// Obviously, this doesn't work because you can't put a lamba in the anonymous type, but how do you do it ?
.Read(read => read.Action(
"Details"
,
"Person"
,
new
{ id = (p => p.person.pkey) } ))
.Update(update => update.Action(
"Update"
,
"Person"
))
.Destroy(destroy => destroy.Action(
"Destroy"
,
"Person"
))
I have a couple of Dropdownlist in columns of a grid, when the page is resized the DDLs are not being resized accordingly.
How can I hook them into the column width on the resize.
This is kind of a follow-up to this one:
https://www.telerik.com/forums/dropdownlist-in-a-non-editable-grid
Thanks
The icon on my date picker is too high... it should be centered in the dropdown box. What CSS do I need to modify to get it to look right?
Hello!
First of all I'm posting tihs in the DropDownTree section but I'm not convinced that the DropDownTree is necessarily the right component for what I want.
Basically I need to display something exactly like the autocomplete component but it must have a hierarchy, so the items displayed in this "autocomplete" can be a parent item or a child item and each child is linked to a parent and should be somehow intended. This looks like what the DropDownTree offers but I'm having several problems working with it.
In order to get my data, I need to call an external service which takes two parameters, the language and the search string (which should be whatever the user typed in the autocomplete box).
This is how I setup my DropDown:
01.
@(Html.Kendo().DropDownTree()
02.
.Name(
"search"
)
03.
//.DataTextField("name")
04.
.Placeholder(
"Search"
)
05.
.Filter(FilterType.Contains)
06.
.MinLength(2)
07.
.DataSource(dataSource => dataSource
08.
.Read(read => read
09.
.Action(
"Search"
,
"Blabla"
,
new
{ culture = Localizer.CultureName })
10.
.Data(
"onAdditionalData"
)
11.
)
12.
)
13.
)
14.
<input type=
"hidden"
id=
"searchFilter"
name=
"searchFilter"
/>
In onAdditionalData, I setup the two parameters that my Search action from the Blabla controller requires:
1.
<script>
2.
function
onAdditionalData() {
3.
return
{
4.
language:
"@Localizer.CultureName"
,
5.
searchString: $(
"#searchFilter"
).val()
6.
};
7.
}
8.
</script>
Since I didn't find an easy way to get the value that the user typed, I'm binding the filtering event like this and setting the value in a hidden field, which is then used by onAdditionalData to pass the search string:
01.
function
dropdowntree_filtering(e) {
02.
//get filter descriptor
03.
var
filter = e.filter;
04.
$(
"#searchFilter"
).val(filter.value);
05.
}
06.
07.
$(
function
() {
08.
$(document).ready(
function
() {
09.
var
dropdowntree = $(
"#search"
).data(
"kendoDropDownTree"
);
10.
dropdowntree.bind(
"filtering"
, dropdowntree_filtering);
11.
});
12.
});
Then my controller calls the service with the 2 parameters and that's fine, I get my results in essentially this format:
01.
[
02.
{
03.
"id"
:851,
04.
"name"
:
"Some name 1"
,
05.
"idParent"
:
null
,
06.
"children"
:[
07.
08.
]
09.
},
10.
{
11.
"id"
:402,
12.
"name"
:
"Some name 2"
,
13.
"idParent"
:
null
,
14.
"children"
:[
15.
{
16.
"id"
:403,
17.
"name"
:
"Some name 3"
,
18.
"idParent"
:402,
19.
"children"
:
null
20.
},
21.
{
22.
"id"
:404,
23.
"name"
:
"Some name 4"
,
24.
"idParent"
:402,
25.
"children"
:
null
26.
}
27.
]
28.
},
29.
{
30.
"id"
:923,
31.
"name"
:
"Some name 5"
,
32.
"idParent"
:
null
,
33.
"children"
:[
34.
{
35.
"id"
:929,
36.
"name"
:
"Some name 6"
,
37.
"idParent"
:923,
38.
"children"
:
null
39.
}
40.
]
41.
},
42.
{
43.
"id"
:728,
44.
"name"
:
"Some name 7"
,
45.
"idParent"
:727,
46.
"children"
:[
47.
{
48.
"id"
:734,
49.
"name"
:
"Some name 8"
,
50.
"idParent"
:728,
51.
"children"
:
null
52.
}
53.
]
54.
},
55.
{
56.
"id"
:757,
57.
"name"
:
"Some name 9"
,
58.
"idParent"
:727,
59.
"children"
:[
60.
{
61.
"id"
:763,
62.
"name"
:
"Some name 10"
,
63.
"idParent"
:757,
64.
"children"
:
null
65.
}
66.
]
67.
},
68.
{
69.
"id"
:405,
70.
"name"
:
"Some name 11"
,
71.
"idParent"
:
null
,
72.
"children"
:[
73.
{
74.
"id"
:406,
75.
"name"
:
"Some name 12"
,
76.
"idParent"
:405,
77.
"children"
:
null
78.
}
79.
]
80.
}
81.
]
Now my problem is that I don't know how to build a result set that the dropdowntree can display properly. I've tried to build a list of DropDownTreeItem like this:
01.
public
async Task<JsonResult> Search(
string
language,
string
searchString)
02.
{
03.
IReadOnlyCollection<MyDto> results = await _myService.Search(language, searchString);
04.
IList<DropDownTreeItem> items =
new
List<DropDownTreeItem>();
05.
foreach
(var r
in
results)
06.
{
07.
DropDownTreeItem item =
new
DropDownTreeItem
08.
{
09.
Id = r.Id?.ToString(),
10.
Text = r.Name,
11.
HasChildren = r.Children.Count > 0
12.
};
13.
if
(r.Children.Count > 0)
14.
{
15.
foreach
(var c
in
r.Children)
16.
{
17.
item.Items.Add(
new
DropDownTreeItem
18.
{
19.
Id = c.Id?.ToString(),
20.
Text = c.Name,
21.
HasChildren =
false
22.
});
23.
}
24.
}
25.
items.Add(item);
26.
}
27.
return
Json(items);
28.
}
But that doesn't really work, the autocomplete does not contain any items then, for some reason that also doesn't populate anything in the autocomplete (I get "no data found" even though there are items). From the examples I've seen, it seems that DropDownTreeItem needs to call the search method recursively to get its children and this doesn't work for me because my service already returns me all the relevant children based on my search string.
I've tried using the ToTreeDataSourceResult method like this:
1.
public
async Task<JsonResult> Search(
string
language,
string
searchString)
2.
{
3.
IReadOnlyCollection<MyDto> results = await _myService.Search(language, searchString);
4.
var tree = results.ToTreeDataSourceResult(
new
DataSourceRequest(), a => a.Id, a => a.IdParent);
5.
return
Json(tree.Data);
6.
}
that also doesn't populate anything in the autocomplete. (I get "no data found" even though the tree.Data has data).
I'm starting to think that this DropDownTree is not the right component and maybe I can achieve what I want with a simple AutoComplete and some styling ?
Hopefully my problem is clear enough with those details.
Any help would be greatly appreciated,
Thanks!
Hi All,
I have razor page that gets data source on server side from "public async Task OnGetAsync()". I was able to get data from api and have it set to List successfully. Now, how can I set this datasource to my Kendo Grid? Thanks in Advance!
@(Html.Kendo().Grid<
UserList
>().Name("grid")
.Groupable()
.Sortable()
.Editable()
.Scrollable()
.ToolBar(x => x.Excel())
.Columns(columns =>
{
columns.Bound(column => column.Id);
columns.Bound(column => column.firstName);
columns.Bound(column => column.lastName);
columns.Command(column =>
{
column.Edit();
column.Destroy();
});
})
.Excel(excel => excel
.FileName("Export.xlsx")
.Filterable(true)
.ProxyURL("/Admin?handler=Save")
)
.DataSource(ds => ????
.PageSize(10)
)
.Pageable()
)
I have an MVC grid with inline editing set and the user is able to select an entire row. I've managed to change the hover background color of a non-selected row by changing some CSS. When the user selects a row I'm also able to change the background color of the selected row. However, what I cannot seem to change is the hover color of the selected row. It's a deep blue and I'm unable to change it.
This is the CSS code I've created:
.k-grid .k-state-selected {<
br
> background-color: #C4FAEC;<
br
> color: #000000;<
br
>}<
br
>
.k-grid .k-state-selected:hover {<
br
> background-color: #C4FAEC;<
br
> color: #000000;<
br
>}<
br
>
.k-grid td.k-state-selected:hover, .k-grid tr:hover {<
br
> color: #000000;<
br
> background-color: #C4FAEC;<
br
>}<
br
>