I have a table called Priority and it has a column called IconUrl that is used to store the path of the icons as shown below:
| ID | Priority | IconUrl
------------------------------------------------------------|
| 0 | Normal | /../../Content/icons/normal.png |
| 1 | Urgent | /../../Content/icons/urgent.png |
| 2 | Blocker | /../../Content/icons/blocker.png |
I want to display icons according to the IconUrl values for each records on the Kendo Grid. I tried some methods as shown below, but none of them was solved the problem yet. How to manage to display just icon images?
columns.Bound(c => c.Priority).ClientTemplate("<img src='" + Url.Content("~/") + "#=IconUrl#' height='62' width='62'/>");
or
columns.Bound(c => c.Priority).ClientTemplate("<img src='" + Url.Content("#=Model.IconUrl#") + "'/>'");
The problem could be caused by the '/../../' at the start of your url.
Open your browsers developer tools, look at the cell can see what url is there.
If your content folder is in your home or project directory then recreating the url with the text from Priority col might work.
columns.Bound(c => c.Priority).ClientTemplate("<img src='" + Url.Content("~/Content/icons/") + "#=Priority.toLowerCase()#.png' height='62' width='62'/>");
The Url.Content function is used to map virtual paths. For example having apps inside other apps. If there is not a tilde at the start of the string passed to the function it will just return the url string unchanged.
So in your second example calling "<img src='" +Url.Content("#=IconUrl#") + "'/>'" will produce the same result as <a src='#=IconUrl#'>
As mentioned on Grid / Basic usage on Telerik page, you can display the image as shown below:
#(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.CustomerViewModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.PriorityDescription)
.ClientTemplate(#"<div class='grid-icon' style='background-image:
url(#:data.IconUrl#);'></div>").Width("40px");
columns.Bound(c => c.ContactTitle).Width(190);
columns.Bound(c => c.CompanyName);
columns.Bound(c => c.Country).Width(110);
})
.HtmlAttributes(new { style = "height: 380px;" })
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Customers_Read", "Grid"))
)
)
<style>
.customer-photo {
display: inline-block;
width: 32px;
height: 32px;
border-radius: 50%;
background-size: 32px 35px;
background-position: center center;
vertical-align: middle;
line-height: 32px;
box-shadow: inset 0 0 1px #999, inset 0 0 10px rgba(0,0,0,.2);
margin-left: 5px;
}
.customer-name {
display: inline-block;
vertical-align: middle;
line-height: 32px;
padding-left: 3px;
}
</style>
Related
I have a landing page where there is one main navigation bar at the top of the page that is set to "fixed-top" so that the navbar follows as the user scrolls down. In my [code-pen example](https://codepen.io/njmark88/pen/YzjxxXb?editors=1000), I have an additional navbar labeled "scrollbar" on top of the "Call To Action" section.
How can I achieve the following:
Once the main "navbar" reaches the position of the "scrollbar", how can I have the main "navbar" push down the "scrollbar" as the user continues to scroll down the page?
I need to set "fixed-top" of the "scrollbar" relative to the top of the "Call To Action" section, not the top of the landing page.
I attempted to set the "scrollbar" to "fixed-top" as well, unfortunately that just aligns it to the top of the page.
I was able to solve the issue with the following code in react :
const LandingPage = () => {
const fixedScrollbarNav = () => {
(window.pageYOffset > 928) ? document.querySelector(".scrollbar-nav").classList.add("fixed-scrollbar") : document.querySelector(".scrollbar-nav").classList.remove("fixed-scrollbar");
};
React.useEffect(() => {
window.addEventListener("scroll", () => fixedScrollbarNav());
return () => window.removeEventListener("scroll", () => fixedScrollbarNav());
}, []);
return (
<>
<div style={{ overflow: "hidden" }}>
<Navbar />
<SearchBar />
<Scrollbar />
<Cta />
<FeaturedCities />
<Contact />
<Footer />
</div>
</>
)
}
export default LandingPage;
By adding an event-listener on scroll, I was able to call a function that adds or removes specific CSS classes that change the position of the scrollbar from relative to fixed and top: 27px
.scrollbar-nav {
position: relative !important;
top: 27px !important;
}
.fixed-scrollbar {
position: fixed !important;
top: 50px !important;
left: 0px !important;
right: 0px !important;
z-index: 99 !important;
}
Here is the sample code, i have a avatar and onclick of it i want to show a small dropdown with logout option and possibly username.
import { Avatar, Layout } from 'antd';
<StyledAvatar size="small"> {initials} </StyledAvatar>
const StyledAvatar = styled(Avatar)`
margin-left: ${({ theme }: { theme: Theme }) => theme.paddings.small}px;
color: black;
background-color: white;
font-weight: bold;
`;
<Dropdown
overlay={menu}
trigger={["click"]}
placement="bottomLeft"
>
<div onClick={e => e.preventDefault()}>
<Avatar size="large" icon={<UserOutlined />} />
</div>
</Dropdown>
We put the avatar component inside the Dropdown component.
Kendo UI Grid in MVC with Conditional Au Custom Command Button
How Conditionally display Destroy or Custom Command button Base on Authorization
I wanna display a Custom Command in kendo MVC grid For users that have Role="Admin"
Like
#if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.IsInRole("Admin"))
{
In my Kendo Grid
#(Html.KendoGrid<Management.Models.Users.UserModel>("dgvUser", "PartialCustomUserModel", false)
.Columns(c => c.Command(cc =>
{
cc.Custom("delete").HtmlAttributes(new
{
#style = #"
color : transparent;
background-position: center center;
background-image: url('../Content/themes/base/images/blue/imgEditUser.png');
background-size: contain;
background-repeat: no-repeat;
height: 28px;
cursor: pointer;"
}).Click("deleteUser");
What can I do?
You can use the following
#(Html.Kendo()
.Grid<YourModel>()
.Name("Grid")
.Columns(columns =>
{
columns.Command(command =>
{
if (User.IsInRole("Admin"))
{
command.Custom("delete").Click("deleteUser");
}
}).Title("Commands");
}))
or easily, instead of adding custom button, just add the destroy button
hope this will help you
I've got a Kendo grid:
<section class="main-window">
#model IEnumerable<SustIMS.Models.ModelTest>
<div class="clear-both">
<div class="field-value" style="height: 30px; border-bottom: 1px solid black">
</div>
<div id="datagrid">
#(Html.Kendo().Grid(Model)
.Name("datagrid_Concessoes")
.Columns(columns =>
{
columns.Bound(c => c.Id).Width(70);
columns.Bound(c => c.Code);
columns.Bound(c => c.Description);
columns.Bound(c => c.CreationDate);
columns.Bound(c => c.CreationUser);
})
.Scrollable()
.Sortable()
.Selectable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetAutoEstradas", "MasterData"))
)
)
</div>
</div>
</section>
Here's the section CSS:
.main-window
{
border: 2px solid gray;
border-radius: 2px;
width: 95%; height: 70%;
background-color: White;
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
box-sizing: border-box;
}
I want the Kendo grid to have the height of its container. I've tried the
.Scrollable(s => s.Height(200))
but it only accepts values in pixels, not in percentage.
How can I set the Kendo grid to fit its container div/section?
PS: I've checked this question but didn't find a solution for me
I was able to get it work by setting height in the onDataBound event handler, like so:
<div id="datagrid">
#(Html.Kendo().Grid<Model>()
.Name("datagrid_Concessoes")
.Columns(columns =>
{
columns.Bound(c => c.Id).Width(70);
columns.Bound(c => c.Code);
columns.Bound(c => c.Description);
columns.Bound(c => c.CreationDate);
columns.Bound(c => c.CreationUser);
})
.Scrollable()
.Sortable()
.Selectable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetAutoEstradas", "MasterData"))
)
.Events(events => events.DataBound("grid1_onDataBound"))
)
function grid1_onDataBound(e) {
$("#datagrid .k-grid-content").attr("style", "height: auto");
}
Remove the .Scrollable() method. Scrollable() forces a fixed height on the grid.
Remove height propery from grid. Sample GridID = #grid
Add DataBound Event to grid;
Events(j=>j.DataBound("DataBound"))
Add Css;
html, body { margin:0; padding:0; height:100%; }
#grid { height: 100%; }
#outerWrapper{ background-color: red; overflow: hidden; }
.k-grid td { white-space: nowrap; overflow: hidden; }
Add Javascript;
function resizeGrid() {
$(".k-grid-content").css({ height: $(".k-grid-content")[0].scrollHeight });
}
setTimeout(function () {
resizeGrid();
}, 150);
i have 10 row grid and content within the grid has a calculated height.
In the grid you can set the height via the htmlattributes section something like this:
.HtmlAttributes(new { style = "height:600px;" })
or
.HtmlAttributes(new { class= "main-window" })
Having tested this on my grid this should work for you:
$(document).ready(function () {
//Get the current window height
var windowHeight = $(window).height();
//record the value of the height to ensure it is showing correctly.
console.log("Original Height" + windowHeight);
//multiply this height by a percentage e.g. 70% of the window height
windowHeight = windowHeight * 0.7;
//record the new modified height
console.log("Modified Height" + windowHeight);
//find my grid and the grid content and set the height of it to the new percentage
$("#baseGrid .k-grid-content").height(windowHeight);
});
I derived my solution from David Shorthose's above. I also needed my grid to resize when the window resized. My page also has a header and footer section which is 225px, so I subtract that out rather than using a percentage. Here is the script I added to my page:
<script>
$(function () {
resizeGrid();
});
$(window.onresize = function () {
resizeGrid();
})
function resizeGrid() {
$("#gridname").height($(window).height() - #Settings.TopBottomMarginHeight);
}
</script>
I moved the 225px into a settings class for easy re-use, which looks like this:
namespace Website
{
public static partial class Settings
{
public static int TopBottomMarginHeight => 225;
}
}
I have a listboxfor in my application which works greats. But to make multiple selection I need to press ctrl and click on the item. How can I change this behavior, so every time I click on the item in the list it selects it and when press again it deselects but only one of the selected items.
My listbox:
#Html.ListBoxFor(m => m.selectedCharts, new SelectList(#Model.Graphs.ToList() )
, new { #class = "select_change" }
)
Or maybe I should use different control for this purpose?
Many thanks
I've used Bootstrap Multiselect before, with great success.
If it cannot be a drop down, use this Checkbox list instead.
I have managed to complete a nice looking listbox where user don't need to press ctrl button to select multiple elements. I want to share with you my work. I have used suggested by MartinHN an amazing extension CheckBoxListFor. You can find it on this website MvcCheckBoxList.
My View Code
#{
var htmlListInfo = new HtmlListInfo(HtmlTag.vertical_columns, 0 , new { #class="styled_list" });
#Html.CheckBoxListFor(model => model.ReportSettings.Ids,
model => model.AvailableGraphs,
graph => graph.Id,
graph => graph.Name,
model => model.SelectedGraphs,
new { #class="styled_checkbox" },
htmlListInfo,
null,
x => x.Name)
}
My CSS:
input.styled_checkbox, input[type="checkbox"]
{
visibility: hidden;
width: 0px;
}
.styled_list
{
background: #aeeefb;
border-radius:5px;
padding: 10px 10px 10px 0;
color: White;
font-weight: bold;
}
.styled_checkbox
{
background: #69D2E7;
cursor: pointer;
display: inline-block;
vertical-align: middle;
margin: 3px 0 3px 0;
padding: 5px;
position: relative;
width: 250px;
border-radius:5px;
}
.styled_checkbox:hover
{
opacity: 0.7;
}
.styled_checkbox:checked+label
{
background: #1a9eed;
}
The check boxes are hidden and labels indicates that element is selected or not. I can't insert pictures but it looks good, but you can off course edit style to your own needs.
Hope that helps anyone