Kendo Editor , negative value restriction - html

I am working for a project with MVC4.
I am using kendo editor template for Incell Editing. Here is a column that is accepting negative value when edited.
Code I am using-
#(Html.Kendo().Grid<Dev.Crm.Web.Models.ViewModel.ProjectViewModel>()
.Name("_projectGrid")
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Columns(columns =>
{
columns.Bound(p => p.FixedPrice).Title(#Dev.Crm.Web.Resources.Shared.Project.Label_FixedPrice).EditorViewData(new { OnChangeCallback = "Product_List_updateProjectChanges" }).Width("15%").EditorTemplateName("Number");
})
.Pageable()
.Sortable()
.Selectable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>model.Id(p => p.TaskID))
.Batch(true)
.Model(model =>
{
model.Id(p => p.ProjectID);
model.Field(p => p.ProjectID).Editable(false);
})
.Read(read => read.Url(#Url.Project_Operation_Read()).Data("Project_List_searchData"))// the name of the javascript function which will return the additional data.
//.Destroy(destroy => destroy.Action("Delete", "Project"))
.Update(update => update.Url(#Url.Project_Operation_SaveCellEdit()))
)
.Events(e => { e.DataBound("Grid_DataBound"); })
)
In cell edit , I can edit this cell, but how do i restrict it from accepting negative values.

Basically I assume that your project has the EditorTemplates under the Shared/EditorTemplate folder. If you have them then for numbers you should use the KendoNumericTextBox widget.
If you do not use the Kendo NumbericTextBox as editor - you better find how to do it.
Once you have that editor template applied you can set the Min option to be equal to 0.

Related

How i can add space in Yii2 kartik gridview?

I'm using Yii2 kartik gridview for displaying orders, i need to add CURRENCY field like
AED 10 but now its showing without space like AED10
Here is my code :
[
'class' => 'kartik\grid\DataColumn',
'attribute' => 'sub_total',
'hAlign' => 'right',
'vAlign' => 'middle',
'format' => ['AED', $currency],
'width' => '12%',
'pageSummary' => true
]
I need space between currency code and price

Kendo MVC Grid Filtering - Filters that consider multiple fields

I have a MVC Kendo grid where one column is a client template that actually uses multiple fields. By default the built in filtering is only applied to the field the column is bound to. How do I override that so it considers both fields. Ie, when I search for "Contains" "De" a column that displays "Detroit, MI" should return.
Here's what I have so far:
MVC View
#(Html.Kendo().Grid<ViewModel>()
.DataSource(dataSource => dataSource
.Custom()
.Transport(t =>
{
t.Read(r => r.Action("StatusGridRead", "DeviceStatus"));
})
.Schema(schema => schema
.Data("Result.Data")
.Total("Result.Total")
.Errors("Result.Errors")
.Model(m =>
{
m.Id(f => f.Id);
m.Field(f => f.StateOrProvince);
m.Field(f => f.City);
...
})
)
)
.Columns(columns =>
{
columns.Bound(c => c.StateOrProvince).Title("City & State").ClientTemplate("#=City#, #=StateOrProvince#");
...
})
.Events(e=>
{
e.Filter("statusGridFilter");
})
.Sortable()
.Filterable(f =>
{
f.Extra(false);
f.Operators(o => o.ForString(s =>
{
s.Clear();
s.Contains("Contains");
s.IsEqualTo("Is Equal To");
s.StartsWith("Starts With");
s.EndsWith("Ends With");
s.DoesNotContain("Does Not Contain");
s.IsNotEqualTo("Is Not Equal To");
}));
})
)
Javascript
function statusGridFilter(e) {
if (e.field == "StateOrProvince") {
//What do I do here?
}
}
I understand if I made a column for city and one for state that would resolve this issue, however I actually have a similar scenario (client template with many string fields displayed) where that won't work and am just picking this as the easiest example. Other than making 1 column for 1 field, I'm open to any other ideas that may solve filtering for this scenario.

How to add SSN mask to a kendo grid filter?

I have a Kendo grid that displays many columns. I have a column for SSN. When user clicks on the filter and types in 123-45-6789 it filters the correct SSN, however, when user types in 123456789 nothing is filtered. Is there any way that it can filter only 9 numbers with or without dashes.
columns.Bound(p => p.SSN)
.Title("SSN")
.Width(100);
.HtmlAttributes(new {style = "height: 579px; width: 110%"})
.Scrollable()
.Sortable()
.Filterable(filterable => filterable
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.Contains("Contains")
.IsEqualTo("Is equal to")
.StartsWith("Starts with")
.IsNotEqualTo("Is not equal to")
)
)
)
You can set the filter to use a kendoMaskedTextBox like this:
<script>
function ssnFilter(element) {
element.kendoMaskedTextBox({
mask: "000-00-0000"
});
};
</script>
#(Html.Kendo().Grid<YourModel>()
.Name("YourGridName")
.Columns(columns =>
{
columns.Bound(p => p.SSN).Filterable(f => f.UI("ssnFilter"));
}
)
Kendo MaskedTextBox documentation
Kendo Grid Filter Customization documentation

Kendo Grid select over multiple pages

I have created a kendo grid using Asp.Net MVC wrappers. I have included a checkbox for selecting multiple rows made the wiring and everything works ok. However, I have issues, when I change page, or do a filtering as the selecting rows/checkbox disappear.
What is the solution for this problem?
You need to use .PersistSelection(true) to ensure rows remain selected when changing pages:
#(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
.Name("rowSelection")
.Columns(columns => {
columns.Bound(o => o.ShipCountry).Width(300);
columns.Bound(p => p.Freight).Width(300);
columns.Bound(p => p.OrderDate).Format("{0:dd/MM/yyyy}");
})
.Pageable(pageable => pageable.ButtonCount(5))
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Multiple))
.PersistSelection(true)
.Navigatable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(m=>m.Id("OrderID"))
.PageSize(6)
.Read(read => read.Action("Orders_Read", "Grid"))
)
Also ensure you have an id column declared in the DataSource, like .Model(m=>m.Id("OrderID")) in the example, otherwise it will fail.
Full details here.
I had issues with the jQuery grid.select() however:
var grid = $('#rowSelection').data('kendoGrid');
var rows = grid.select();
This only seemed to return rows selected on the currently displayed page rather than all the rows selected across all the pages.

Kendo UI grids with dropdown editor templates edit issue

I have a grid with two drop-down list columns which are mapped with Editor Templates in a razor page. All single edit and update is working fine without any issues. But when I click first row to edit and trying to edit second row without update or cancel the first row it automatically close the edit mode of first row and second one made editable. It is fine but when I click back the first row without update or cancel the second row then the values from second row get updated in the first row as well.
How do I stop this issue. By the way it is found by tester not me.. :(
all problems are coming when we try to edit multiple rows without update or cancel the active editable row.
Please help me because I have spent lot of time on it. I am attaching the sample code here..the field name and template names are modified to give simple example.
Grid
#(Html.Kendo().Grid(Model.Employees)
.Name("GridEmployees")
.Columns(columns =>
{
columns.Bound(i => i.Frequency).Title("Frequency").EditorTemplateName("Frequency").ClientTemplate("#:Frequency#").HtmlAttributes(new { #style = "text-align:Left; " }).Width(75);
columns.Bound(i => i.Quarter).Title("Quarter").EditorTemplateName("Quarter").ClientTemplate("#= kendo.toString(Quarter,\"MMM yyyy\") #").HtmlAttributes(new { #style = "text-align:left; " }).Width(75);
columns.Bound(i => i.EmpId).Hidden();
columns.Command(command => command.Edit()).Width(175);
})
.ToolBar(toolbar => toolbar.Create())
.Editable((editable => editable.Mode(GridEditMode.InLine)))
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Multiple))
.Sortable(sortable => sortable
.AllowUnsort(true)
.SortMode(GridSortMode.MultipleColumn))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Model(model =>
{
model.Id(s => s.EmpId);
model.Field(s => s.Frequency);
model.Field(s => s.Quarter);
})
.Create(update => update.Action("CreateEmployee", "Employee"))
.Read(read => read.Action("ReadEmployee", "Employee"))
.Update(update => update.Action("UpdateEmployee", "Employee"))
)
)
Editor Templates
Quarter.cshtml
#using System.Collections
#(Html.Kendo().DropDownListFor(i => i)
.Name("Quarter")
.DataValueField("Id")
.DataTextField("Name")
.BindTo((IEnumerable)ViewBag.Quarters)
.OptionLabel("Select Quarter")
)
Frequency.cshtml
#using System.Collections
#(Html.Kendo().DropDownListFor(i => i)
.Name("Frequency")
.DataValueField("Id")
.DataTextField("Name")
.BindTo((IEnumerable)ViewBag.Frequencies)
.OptionLabel("Select Frequency")
)
Thanks in advance,
Late is better than never...The problem is, that you generate multiple dropdown lists with the same id. Just assign a dynamic ID to the dropdown in the EditorTemplate and you should be fine.
#(Html.Kendo().DropDownListFor(i => i)
.Name("Frequency")
.HtmlAttributes(new { #id = "Frequency_#=UniqueId#" }) //eg. row id
.DataValueField("Id")
.DataTextField("Name")
.BindTo((IEnumerable)ViewBag.Frequencies)
.OptionLabel("Select Frequency")
)