farzinmonsef / WBRS

0 stars 0 forks source link

Kendo #6

Open farzinmonsef opened 6 years ago

farzinmonsef commented 6 years ago

Kendo Grid and else

farzinmonsef commented 6 years ago

Kendo Grid Tooltip

$(document).ready(function () { $("#grid").kendoTooltip({ //filter: "td[1n]||td[2n]", //this filter selects the second column's cells filter: "td:nth-child(2):not(:has(input))", //this filter selects the second column's cells position: "right", Template: " My-Guide: #= ShipName#>", content: function (e) { var dataItem = $("#grid").data("kendoGrid").dataItem(e.target.closest("tr")); var content = 'My Guide: '+dataItem.ShipName; return content; } }).data("kendoTooltip"); });

farzinmonsef commented 6 years ago

Adding On Row Click to the KendoUI Grid

https://www.codeproject.com/Tips/434175/Adding-On-Row-Click-to-the-KendoUI-Grid

var grid = $("#kGrid").kendoGrid({ ... change: function (arg) { var selected = $.map(this.select(), function (item) { return $(item).find('td').first().text(); }); alert(selected); }, });

farzinmonsef commented 6 years ago

A collection of Telerik UI for ASP.NET MVC examples

https://github.com/telerik/ui-for-aspnet-mvc-examples

farzinmonsef commented 6 years ago

Grid Dynamic default values

https://www.telerik.com/forums/dynamic-default-values ............................................................................................................................................................. .ToolBar(toolbar => { toolbar.Create().Text("Add row"); }) ... .Model(model => { model.Id(n => n.ID); model.Field(c => c.count).DefaultValue(<this value needs to be max value + 1>); model.Field(c => c.count).Editable(false); })

............................................................................................................................................................. function onEdit(e) { e.container.find("[name=fieldName]").hide(); } ............................................................................................................................................................. function onEdit(e) { //execute your custom logic to get the max value var maxValue = 5; //check if record is new if (e.model.isNew()) { //set the required field value e.model.set("OrderCount", maxValue + 1); } }

farzinmonsef commented 6 years ago

Use Custom Popup Editors

https://docs.telerik.com/aspnet-mvc/helpers/grid/how-to/editing/custom-popup-editor https://github.com/telerik/ui-for-aspnet-mvc-examples

@(Html.Kendo().Grid().Name("persons") .DataSource(dataSource => dataSource .Ajax() .Model(model => model.Id(m => m.PersonID)) .Read(read => read.Action("GetPersons", "Home")) .Update(up => up.Action("UpdatePerson", "Home")) ) .Columns(columns => { columns.Bound(c => c.PersonID).Width(200); columns.Bound(c => c.Name); columns.Bound(c => c.BirthDate).Format("{0:g}"); columns.Command(cmd => cmd.Edit()); })

.Pageable()
.Sortable()
.Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("Person"))

)

farzinmonsef commented 6 years ago

NEXT 3 BOX ARE RELATED

1/3) DynamicDataValues-Sample = PersonController

using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Linq; using System.Net; using System.Web; using System.Web.Mvc; using Kendo.Mvc.Extensions; using Kendo.Mvc.UI; using DynamicDataValues.Models;

namespace DynamicDataValues.Controllers { public class PersonController : Controller { private GridEntities db = new GridEntities();

    public ActionResult Index()
    {
        return View();
    }

    public ActionResult People_Read([DataSourceRequest]DataSourceRequest request)
    {
        IQueryable<Person> people = db.People;
        DataSourceResult result = people.ToDataSourceResult(request, person => new {
            id = person.id,
            name = person.name,
            salary = person.salary
        });

        return Json(result);
    }

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult People_Create([DataSourceRequest]DataSourceRequest request, Person person)
    {
        if (ModelState.IsValid)
        {
            var entity = new Person
            {
                name = person.name,
                salary = person.salary
            };

            db.People.Add(entity);
            db.SaveChanges();
            person.id = entity.id;
        }

        return Json(new[] { person }.ToDataSourceResult(request, ModelState));
    }

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult People_Update([DataSourceRequest]DataSourceRequest request, Person person)
    {
        if (ModelState.IsValid)
        {
            var entity = new Person
            {
                id = person.id,
                name = person.name,
                salary = person.salary
            };

            db.People.Attach(entity);
            db.Entry(entity).State = EntityState.Modified;
            db.SaveChanges();
        }

        return Json(new[] { person }.ToDataSourceResult(request, ModelState));
    }

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult People_Destroy([DataSourceRequest]DataSourceRequest request, Person person)
    {
        if (ModelState.IsValid)
        {
            var entity = new Person
            {
                id = person.id,
                name = person.name,
                salary = person.salary
            };

            db.People.Attach(entity);
            db.People.Remove(entity);
            db.SaveChanges();
        }

        return Json(new[] { person }.ToDataSourceResult(request, ModelState));
    }

    [HttpPost]
    public ActionResult Excel_Export_Save(string contentType, string base64, string fileName)
    {
        var fileContents = Convert.FromBase64String(base64);

        return File(fileContents, contentType, fileName);
    }

    [HttpPost]
    public ActionResult Pdf_Export_Save(string contentType, string base64, string fileName)
    {
        var fileContents = Convert.FromBase64String(base64);

        return File(fileContents, contentType, fileName);
    }

    protected override void Dispose(bool disposing)
    {
        db.Dispose();
        base.Dispose(disposing);
    }

    [HttpPost]
    public void SetDate()
    {

        Session["TestValue"] = DateTime.Now.ToString("HHmm", System.Globalization.CultureInfo.GetCultureInfo("en-US"));
    }

    [HttpPost]
    public ActionResult getSession()
    {
        return Json((Session["TestValue"] ?? ""), JsonRequestBehavior.AllowGet);
        //return new JsonResult ({new data: Session["TestValue"] ?? "" });
    }
}

}

farzinmonsef commented 6 years ago

2/3) DynamicDataValues-Sample = PersonController Index

@{ Layout = "~/Views/Shared/_Layout.cshtml"; }

@@Html.ActionLink("SetDate", "SetDate", "Person", null, null)@

@type="submit" onclick="callClick" @

@(Html.Kendo().Grid() .Name("grid") .Columns(columns => { columns.Bound(c => c.id).Visible(false); columns.Bound(c => c.name); columns.Bound(c => c.salary); columns.Command(command => { command.Edit(); command.Destroy(); }).Width(180); }) .ToolBar(toolbar => { toolbar.Create(); toolbar.Excel(); toolbar.Pdf(); }) .ColumnMenu() .Editable(editable => editable.Mode(GridEditMode.PopUp)) .Pageable() .Navigatable() .Selectable(selectable => { selectable.Mode(GridSelectionMode.Single); selectable.Type(GridSelectionType.Row); }) .Sortable(sortable => { sortable.SortMode(GridSortMode.SingleColumn); }) .Filterable() .Scrollable(scrollable => scrollable.Enabled(false)) .Events(events => { events.Remove("onRemove"); events.Save("onSave"); events.SaveChanges("onSaveChanges"); events.Cancel("onCancel"); events.Change("onChange"); events.Edit("onEdit"); events.ColumnMenuInit("onColumnMenuInit"); events.ColumnLock("onColumnLock"); }) .DataSource(dataSource => dataSource .Ajax() .ServerOperation(true) .Model(model => { model.Id(p => p.id); //model.Field(c => c.salary).DefaultValue(Session["TestValue"] ?? "-"); //model.Field(c => c.salary).Editable(false); //model.Field(p => p.OrderID).Editable(false); }) //.Model(model => model.Id(p => p.id)) .Read(read => read.Action("People_Read", "Person")) .Create(create => create.Action("People_Create", "Person")) .Update(update => update.Action("People_Update", "Person")) .Destroy(destroy => destroy.Action("People_Destroy", "Person")) ) .Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("PersonEdit")) )

farzinmonsef commented 6 years ago

3/3) DynamicDataValues-Sample = PersonController PersonEdit

@model DynamicDataValues.Models.Person

@{ ViewBag.Title = "Edit"; }

Custom Edit

@using (Html.BeginForm()) { @Html.AntiForgeryToken()

<div class="form-horizontal">
    <h4>Student</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    @Html.HiddenFor(model => model.id)

    <div class="form-group">
        @Html.LabelFor(model => model.name, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.name, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.name, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.salary, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.salary, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.salary, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Save" class="btn btn-default" />
        </div>
    </div>
</div>

}

@Html.ActionLink("Back to List", "Index")

@@section Scripts { @Scripts.Render("~/bundles/jqueryval") }@

farzinmonsef commented 6 years ago

Show ALERT WINDOW

https://stackoverflow.com/questions/17790107/how-to-return-modelstate-errors-to-kendo-grid-in-mvc-web-api-post-method

farzinmonsef commented 6 years ago

MultiSelectList LISTBOX In MVC

https://www.codeproject.com/Articles/1063846/Step-By-Step-Implementation-of-MultiSelectList-In

https://stackoverflow.com/questions/21826280/selectedvalues-not-working-in-multiselectlist-mvc

https://visualstudiomagazine.com/articles/2017/06/09/tip-aspnet-mvc-multiselect-dropdown.aspx

https://www.dropbox.com/s/i0bhymspkb0ofhw/Sample-MultiSelect.zip?dl=0

farzinmonsef commented 6 years ago

ss.zip.003.zip ss.zip.004.zip ss.zip.005.zip ss.zip.002.zip hjsplit.zip

ss.zip.001.zip