How to generate a custom button that submits cell data from its uid in Kendo UI Grid MVC?

Kenchi

I am new to Kendo UI for ASP.NET MVC and I wanted to create a customized action button on a grid and retrieve some data when that button is clicked based on each unique row.

Here is my grid's code

@(Html.Kendo()
      .Grid<PromotionVM>()
      .Name("PromotionsGrid")
      .Columns(columns =>
      {
          columns.Bound(c => c.Merchant);
          columns.Bound(c => c.Item);
          columns.Bound(c => c.Image);
          columns.Bound(c => c.DiscountRate);
          columns.Command(command => command.Custom("Approve").Click("ApprovePromotion"))
              .Title("Action");
      })
      .DataSource(source =>
      {
          source.Ajax()
              .Model(model => model.Id(field => field.Id))
              .Read(read => read.Action("GetPromotions", "Promotion"));
      })
      )

Here is the PromotionVM:

    [Required]
    public Guid Id { get; set; }
    public string Merchant { get; set; }
    public string Branch { get; set; }
    public string Item { get; set; }
    public string Image { get; set; }
    public decimal DiscountRate { get; set; }

and here is the javascript function that I want to call to do an ajax request when I am able to get the "Id" column value from the Grid upon button click.

<script type="text/javascript">
function ApprovePromotion(e) {

}
</script>

Notice that the function is empty because I have no idea what to do here yet.

Please help if you can.

Thanks in advance.

Steve Greene

Pretty open ended question, but as an example:

<script type="text/javascript">
function ApprovePromotion(e) {
    e.preventDefault();
    // grab data for row
    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));

    // make ajax call
    $.ajax({
        url: '@Url.Action("MyAction", "MyController")',
        type: "POST",
        data: {
            // pass data to controller parameters
            ItemID: dataItem.Id,
            OtherField: dataItem.OtherField
        },
        success: function (response) {
            // On success do something. I'll switch to index
            window.location.href = '@Url.Action("Index", "MyController")';
        }
    });

}
</script>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Kendo UI: Conditionally preventing a Tooltip from being displayed on a Grid cell

How to transpose rows and columns in a Kendo UI grid in MVC application?

Kendo Grid - Render custom HTML based on the Column cell data value

Kendo Grid: Drag and Drop Cell Data From One Grid Into another

kendo ui grid data not showing from php

How to load manually data in kendo ui grid

How to conditionally format Kendo UI grid cell (depending on values) razor

How to render Kendo UI grid from AJAX response data?

Kendo UI, How to manually call validate() on kendo grid cell

How to custom tooltip such as contains some button in grid's cell tooltip in Kendo UI MVC?

Kendo UI Grid - How to save current radio button state

Kendo-UI Grid (w/ MVC Wrappers) : How do I create a button that navigates to details page

How to update and reload the datasource of a Kendo UI MVC grid from clientside upon search

Sorting on Kendo UI MVC Grid

how to check and change color of cell value in kendo ui grid

Kendo UI Grid cell coloring in MVC4

Kendo UI MVC Grid Not Updating

Adding "active" color for custom Kendo UI grid button

Display Custom Command Button Kendo UI Grid in MVC with Conditional Authorization Role

UI-Grid with button in custom cell template - How to cancel row select event?

How to change the background of a cell dynamically in a Kendo MVC UI Grid?

Passing model from Kendo Mvc UI Grid to javascript function

How to Generate data in textbox Create data in gridline Grid Kendo UI

Kendo UI access detail grid instance from widget in its editor

Kendo Grid UI with custom function

Kendo UI Grid MVC - Why does an Edit button appear at the end of each row when in-cell mode is set?

Custom template in kendo-ui grid column with inconsistent data type

exporting data from Kendo-UI grid

Custom sort for custom render cell Data Grid Material UI