This is a migrated thread and some comments may be shown as answers.

how we can dont mack grid in mvc insert more than number of the other cell and add validation on cell

1 Answer 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mohammed
Top achievements
Rank 1
Mohammed asked on 04 Aug 2018, 02:44 PM
@(Html.Kendo().Grid<sss.ViewModels.StudentMarkVM>()
 
               .Name("grid")
               .Columns(columns =>
               {
 
                   columns.ForeignKey(c => c.StudentId, (System.Collections.IEnumerable)ViewData["students"], "Id", "NameEn");
                   columns.Bound(c => c.Name).Hidden();
                   columns.ForeignKey(c => c.MarkStructureId, (System.Collections.IEnumerable)ViewData["markStructures"], "Id", "NameEn");
                   columns.Bound(c => c.Mark);
                   columns.Bound(c => c.FullMark);
                   //.ClientTemplate(Html.Kendo().NumericTextBox<double>()
                   //                            .Name("Mark_#=Mark#")
                   //                            //.Value("#=order#")
                   //                            .HtmlAttributes(new { value = "#=Mark #" })
                   //                            .Format("{0:n0}")
                   //                            .Min(0)
                   //                            .Max(100000)
                   //                            .Step(1)
                   //                            .Decimals(0)
                   //                            .Events(ev => ev.Change("numericBoxChanged"))
                   //                            .ToClientTemplate().ToHtmlString());
                   columns.Bound(c => c.IsActive).Hidden();
                   columns.Bound(c => c.Note).Hidden();
                   columns.Bound(c => c.UserDefined1).Hidden();
                   columns.Bound(c => c.UserDefined2).Hidden();
                   columns.Bound(c => c.UserDefined3).Hidden();
                   columns.Bound(c => c.UserDefined4).Hidden();
                   //columns.Bound(c => c.CreationUserName).Hidden();
                   //columns.Bound(c => c.CreationDate).Hidden().Format("{0:MM/dd/yyyy H:mm}");
                   //columns.Bound(c => c.LastUpdateUserName).Hidden();
                   //columns.Bound(c => c.LastUpdateDate).Hidden().Format("{0:MM/dd/yyyy H:mm}");
 
               })
              .ToolBar(toolbar =>
              {
                  toolbar.Save();
                  toolbar.Excel();
                  toolbar.Pdf();
              })
              .ColumnMenu()
              .Editable(editable => editable.Mode(GridEditMode.InCell))
          .HtmlAttributes(new { style = "height: 500px" })
              .Selectable(selectable =>
              {
                  selectable.Mode(GridSelectionMode.Single);
                  selectable.Type(GridSelectionType.Cell);
              })
              .Sortable(sortable =>
              {
                  sortable.SortMode(GridSortMode.SingleColumn);
              })
              .HtmlAttributes(new { style = "height: 500px" })
          .Events(ev => ev.DataBound("db"))
              .Filterable()
              .Scrollable()
             .DataSource(dataSource => dataSource
         .Ajax()
         .Model(model =>
         {
             model.Id(p => p.Id);
             model.Field(p => p.StudentId).Editable(false);
             model.Field(p => p.Name).Editable(false);
             model.Field(p => p.MarkStructureId).Editable().Editable(false);
 
         })
        .Read(read => read.Action("StudentMarks_Read2", "StudentMarks", Model))
         //.Update("StudentMark_Update", "StudentMarks")
         .Update(update => update.Action("StudentMark_Update", "StudentMarks"))
 
         )
    )

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 07 Aug 2018, 12:23 PM
Hi Mohammed,

Based on the provided information I assume that the requirement is to create a validation rule which validates that the Mark field is less than the Full Mark field. Please correct me if I am wrong.

A possible solution is to create a Custom Validation rule with the above condition.

e.g.

    (function ($, kendo) {
    $.extend(true, kendo.ui.validator, {
        rules: { // custom rules
            markvalidation: function (input, params) {
                if (input.is("[name='Mark']") && input.val() != "") {
                    var grid = $('#grid').data('kendoGrid');
                    var dataItem = grid.dataItem(input.parents('tr'));
                    input.attr("data-markvalidation-msg", "Mark should be less than Full Mark!");
                    return +input.val() < dataItem.FullMark;
                }
 
                return true;
            }
        },
        messages: { //custom rules messages
            markvalidation: function (input) {
                // return the message text
                return input.attr("data-val-markvalidation");
            }
        }
    });
})(jQuery, kendo);

For your convenience attached you will find a small sample which demonstrates the above approach.


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Mohammed
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or