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

Dropdown Menu in Grid Row with Authorization Service

3 Answers 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ali
Top achievements
Rank 1
Ali asked on 25 Oct 2019, 12:11 PM

Hello. I am trying to create the below inside a Grid.

                     <div class="btn-group">
                                        <button data-toggle="dropdown" class="btn btn-outline-dark btn-sm"><i class="fa fa-ellipsis-h"></i></button>
                                        <ul class="dropdown-menu">
                                            <li><a class="dropdown-item" asp-page="./Details" asp-route-id="@item.ID"><i class="fa fa-eye"></i> Details</a></li>
                                            @if ((await AuthorizationService.AuthorizeAsync(
                                                  User, item,
                                                  PaymentOperations.Update)).Succeeded)
                                            {
                                                <li><a class="dropdown-item" asp-page="./Edit" asp-route-id="@item.ID"><i class="fa fa-pencil"></i> Edit</a></li>
                                            }
                                            @if ((await AuthorizationService.AuthorizeAsync(
                                                User, item,
                                                PaymentOperations.Delete)).Succeeded)
                                            {
                                                <li><a class="dropdown-item" asp-page="./Delete" asp-route-id="@item.ID"><i class="fa fa-trash"></i> Delete</a></li>
                                            }
                                            </ul>
                                    </div>

Sample Code will be much appreciated.

Regards.

3 Answers, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 30 Oct 2019, 11:16 AM

Hello, Ali,

The Kendo UI Grid for ASP.NET Core column template is executed immediately and will not change when the success/fail has returned its results.

There are few options I can think of:

  • Use the databound event and make a regular ajax call and use the success callback to alter the html programmatically
  • Place the grid declaration inside the conditional statement
  • Assess the authentication prior to the grid declaration so it is already available and causes no delay

@{
    var iSAuthorized = false; // evaluate the condition here
}

// Use it in the columns definition

.Columns(columns =>
{
     columns.Bound(p => p.OrderID).Filterable(false);
     columns.Bound(p => p.Freight);
     if (iSAuthorized)
     {
           columns.Bound(p => p.EmployeeID);
      }
       else 
      {
            columns.Bound(p => p.CustomerID);
      }
 })

Let me know what you think and if you need further information. 

Kind Regards,
Alex Hajigeorgieva
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.
0
Ali
Top achievements
Rank 1
answered on 13 Nov 2019, 05:09 PM

Hello Alex, 

Thanks for the feedback and sorry for the delay.

I try using to last options with the provided code sample, but did not work since the authorization is check on every loop of the item. i.e, for each item check against the authorization whether the item can be edit or delete by the user. Based on the resulted authorization. 

Kindly provide sample code for the first two options.

Thank you.

0
Alex Hajigeorgieva
Telerik team
answered on 18 Nov 2019, 02:03 PM

Hi, Ali,

The Kendo UI Grid bound column has an Editable() method that could be used for each cell/row:

https://docs.telerik.com/aspnet-core/api//Kendo.Mvc.UI.Fluent/GridBoundColumnBuilder#editablesystemstring

We have a runnable example in the JavaScript API that shows how you could use that property:

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/configuration/columns.editable

In case this is not suitable, can you please provide an example how this should work - what is the workflow and how is the authorization per item reflected in the model?

We need a better understanding of the workflow, the model and the authorization context to provide you with a specific advice suited for the exact use case scenario.

Kind Regards,
Alex Hajigeorgieva
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
Ali
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Ali
Top achievements
Rank 1
Share this question
or