Telerik Forums
UI for ASP.NET Core Forum
2 answers
2.0K+ views

Hi,

I'm using the UI grid in ASP.NET Core using local data.  The grid is populated using the page model.

If the user wishes to delete a record, after confirmation, I use an Ajax call to the controller action to perform some magical work and delete the selected record.  The ajax call returns successfully, with the updated record set...minus the recently deleted record.

For the life of me, I can't get the newly updated json dataset to refresh the grid.  Is this even possible?

Page model

public class RoleListViewModel {
    public string GridTitle { get; set; }
    public IEnumerable<RoleGrid> RoleList { get; set; }
}

 

Page code with the grid.

@(Html.Kendo().Grid<RoleGrid>(Model.RoleList)
    .Name("roleGrid")
    .Columns(columns => {
        columns.Bound(m => m.RoleId).Hidden();
        columns.Bound(m => m.Name)
            .Width(100)
            .Title("Name");
        columns.Bound(m => m.Description)
            .Width(212)
            .Title("Description");
        columns.Command(command => {
            command.Custom("EditRole")
                .Text("Edit")
                .HtmlAttributes(new { @class = "ds-button", @style = "color: #000000; border: 1px solid #000000;" })
                .Click("editRole");
            command.Custom("CopyRole")
                .Text("Copy")
                .HtmlAttributes(new { @class = "ds-button", @style = "color: #000000; border: 1px solid #000000;" })
                .Click("copyRole");
            command.Custom("DeleteRole")
                .Text("Delete")
                .HtmlAttributes(new { @class = "ds-button", @style = "color: #000000; border: 1px solid #000000;" })
                .Click("deleteRole");
        })
            .Width(100);
    })
    .HtmlAttributes(new { style = "height: 517px; color: #323232; font-weight: 400; font-size: 14px;" })
    .Pageable(pageable => pageable
        .Input(true)
        .PreviousNext(true)
        .Refresh(true)
        .PageSizes(true)
    )
    .Filterable()
    .ToolBar(t => t.Search())
    .Selectable(select => select
        .Mode(GridSelectionMode.Single)
        .Type(GridSelectionType.Row)
    )
    .Sortable(s => s.AllowUnsort(false))
    .Search(s => {
        s.Field(c => c.Name);
        s.Field(c => c.Description);
    })
    .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false)
        .Model(model => {
            model.Id(m => m.RoleId);
            model.Field(m => m.Name);
            model.Field(m => m.Description);
        })
        .PageSize(10)
    )
)

 

Controller delete method

public async Task<ActionResult> DeleteAjax([DataSourceRequest]DataSourceRequest request, string roleId) {
    if (roleId != null) {
        //do some magical code here after selected record is deleted.
 
        return Json(GetRoles().ToDataSourceResult(request));
    }
    else {
        return Json(GetRoles().ToDataSourceResult(request));
    }
}

 

And finally, the jquery code to handle deleting the selected record

function deleteRole(e) {
    e.preventDefault();
 
    var grid = this;
    var row = $(e.currentTarget).closest("tr");
 
    selectedRole = this.dataItem($(e.currentTarget).closest("tr"));
    $('#confirmDeleteItem').text('Delete the ' + selectedRole.Name + ' role?');
    wnd.center().open();
 
    $("#yes").click(function () {
        wnd.close();
 
        $.ajax({
            type: "POST",
            url: '@Url.Action("DeleteAjax", "Role")',
            data: { roleId: selectedRole.RoleId },
            dataType: "json",
            success: function (response) {
                var grid = $('#roleGrid').data('kendoGrid');

 

                //response.data returns an array of object with roleId, name and description

                //the following call clears out the grid data but the grid still shows the correct # of records left

                grid.dataSource.read(response.data({ RoleID: roleId, Name: name, Description: description }));
            }
        });
    });
 
    $("#no").click(function () {
        wnd.close();
    });
}

 

Any suggestions on how to best load the response array after the ajax call?

 

I realize this is not ideal as it's not server or client side dedicated.

 

Thanks.

Jason

 

Jason
Top achievements
Rank 1
Veteran
 answered on 24 Jan 2020
1 answer
445 views

Hello,

We have VS 2019 installed on build server (Azure DevOps 2019).

Project builds perfectly fine using VS 2019.

However using Azure DevOps build pipeline, we are getting unable to resolve error.

Please take a look at this screenshot and suggest a probable solution.

Thank you

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
  <add key="http_proxy" value="http://..." />
  <add key="https_proxy" value="https://..." />
  </config>
  <packageSources>
    <add key="Telerik" value="https://nuget.telerik.com/nuget/" />
  </packageSources>
  <packageSourceCredentials>
    <Telerik>
      <add key="Username" value="..." />
      <add key="ClearTextPassword" value="..." />
    </Telerik>
  </packageSourceCredentials>
</configuration>

 

StuartLittle
Top achievements
Rank 1
 answered on 24 Jan 2020
1 answer
120 views

hello -- I'm using a panel bar in an MVC app and would like for it to fill the available space,whether the user is looking at the app on a big screen or phone. Specifically, I would like for the panelbar's height to be the same as the viewport and then, when the page is loaded, each of the 5 sections in the panel bar should shrink or grow dynamically to fill the entire panelbar control with no white space left underneath.

Is there a way to accomplish this?

 

thanks

Yvette Whitaker

 

Petar
Telerik team
 answered on 23 Jan 2020
3 answers
4.8K+ views

Hello,

I am working on a .net core web application which builds perfectly fine on my local machine.

We have VS 2019 installed on our build machine. I am able to build successfully without any errors inside Visual Studio.

However, when using TFS 2017 on build machine to build the project, I am getting "No packages exist with this id in source(s): Telerik"

I was just wondering if you could help me with a probable solution? 

Thank you.

 

Petar
Telerik team
 answered on 23 Jan 2020
3 answers
278 views
I see the example in the docs setting a custom datasource, but I dont see any mention of using Ajax for the datasource binding?  It looks like this wont work with razorpages using one of the page handlers for the datasource read methods. So I guess another option is to use a web api handler and use that?
Petar
Telerik team
 answered on 22 Jan 2020
3 answers
983 views

Hello,

I have the following grid implementation:

       <kendo-grid name="grid"
                    auto-bind="true"
                    selectable="multiple, row"
                    persist-selection="true"
                    on-change="Grid_SelectionChanged"
                    on-data-bound="Grid_Loaded"
                    on-remove=""
                    resizable="true">
            <datasource type="DataSourceTagHelperType.Ajax" auto-sync="false" server-filtering="true" server-sorting="true" page-size="10"
                        on-request-end="@MODAL.RequestEndFunctionName" on-error="@MODAL.ErrorHandlerFunctionName">
                <transport>
                    <read url="@Url.Action("ReadItemList", "Users", new { Area = "Admin" })" />
                    <create url="@Url.Action("Create", "Users", new { Area = "Admin" })" />
                    <destroy url="@Url.Action("Delete", "Users", new { Area = "Admin" })" />
                    <update url="@Url.Action("UpdateFromGrid", "Users", new { Area = "Admin" })" />
                </transport>
                <schema>
                    <model id="Id">
                        <fields>
                            <field name="Enabled" type="boolean" default-value="true"></field>
                            <field name="LockoutEnabled" type="boolean" default-value="false"></field>
                            <field name="Id" type="Guid"></field>
                            <field name="UserName" type="string"></field>
                            <field name="Email" type="string"></field>
                            <field name="PhoneNumber" type="string"></field>
                        </fields>
                    </model>
                </schema>
            </datasource>
            <groupable enabled="true" />
            <editable mode="inline" />
            <filterable enabled="true" />
            <sortable enabled="true" />
            <pageable button-count="5" refresh="true" page-sizes="new int[] { 5, 10, 20, 50, 100, 1000 }" />
            <columns>
                <column selectable="true" width="37"></column>
                <column field="Id" title="Id" hidden="true"></column>
                <column field="Enabled"
                        title="Engedélyezett?"
                        template="#= getCheckboxHtml(Enabled) #"
                        editor="ZBoolEditor"
                        min-screen-width="60"
                        width="150"></column>
                <column field="UserName" title="User name" min-resizable-width="180" width="360" html-attributes='new Dictionary<string, object> { ["style"] = "font-weight: bold;" }'></column>
                <column field="Email" title="E-mail address" min-screen-width="180" width="360"></column>
                <column field="PhoneNumber" title="Phone number" min-screen-width="180" width="360"></column>
                <column field="LockoutEnabled"
                        title="Locked"
                        template="#= getLockedHtml(LockoutEnabled) #"
                        editor="ZBoolEditor"
                        min-screen-width="600"></column>
                <column title="Műveletek" width="150">
                    <commands>
                        <column-command text=" " name="edit" visible="false"></column-command>
                        <column-command text="<span class='fas fa-edit'></span>" name="editinpopup" click="Grid_EditInPopup"></column-command>
                        <column-command text="<span class='k-icon k-i-close'></span>" name="custom" click="Grid_RemoveItem"></column-command>
                    </commands>
                </column>
            </columns>

        </kendo-grid>

My problem that the client side validaion not working, I can leave the empty cell without any validation error message and I can press the Update button without restriction. I have data annotations in my model, for example:

        [Required(ErrorMessage = "'{0}' mezÅ‘ megadása kötelezÅ‘!")]
        [Display(Name = "E-mail cím")]
        [EmailAddress(ErrorMessage = "Az e-mail cím formátuma nem érvényes!")]
        [StringLength(255, ErrorMessage = "A(z) '{0}' mezÅ‘ hossza minimum {2}, maximum {1} karakter lehet!", MinimumLength = 5)]
        [GridFastEditEnabled()]
        public string Email { get; set; }

Thank you for help!

 

Alex Hajigeorgieva
Telerik team
 answered on 21 Jan 2020
1 answer
231 views

Hi, has anyone a running sample of a ListView? Here is my code

the returning json from OnPostReadThumbnails looks good, but the ListView is emtpy

{"data":[{"slfd":"0","sdatname":"Test"}],"total":1,"aggregateResults":null,"errors":null}

 

cshtml.cs

public class IndexModel : PageModel
{
    private readonly ILogger<IndexModel> _logger;
 
    public static IList<ThumbnailViewModel> thumbs;
    public IndexModel(ILogger<IndexModel> logger)
    {
        _logger = logger;
    }
 
    public void OnGet()
    {
        if(thumbs == null)
        {
            thumbs = new List<ThumbnailViewModel>();
            thumbs.Add(new ThumbnailViewModel { SLFD = "0", SDATNAME = "Test" });
        }
    }
 
    public JsonResult OnPostReadThumbnails([DataSourceRequest] DataSourceRequest request)
    {
        return new JsonResult(thumbs.ToDataSourceResult(request));
    }
}

cshtml

<script type="text/x-kendo-tmpl" id="template">
    <div class="product">
        <h3>#:SDATNAME#</h3>
        <h1>#=SLFD#</h1>
        <h2>SDATNAME</h2>
    </div>
</script>
<div class="demo-section k-content wide">
    @(Html.Kendo().ListView<Data.ThumbnailViewModel>()
        .Name("listView")
        .TagName("div")
        .ClientTemplateId("template")
        //.Scrollable(ListViewScrollableMode.Endless)
        .DataSource(ds => ds.Ajax()
            .Read(read => read.Url("/Index?handler=ReadThumbnails").Data("forgeryToken"))
        )
        .Pageable()
    )
</div>

Tsvetomir
Telerik team
 answered on 21 Jan 2020
5 answers
394 views

Been trying to determine the correct configuration using tag helpers for the tool tip and so far, documentation nor demos have helped. According to docs, the "content" property could call a script which does not seem to work.  Using the property "context-hander" does but ten the template set does not work.  GetPersonData below returns a JSON object with one property: EmployeeId.

 

 

HTML

<div>
    <span id="PersonInfo" class="fas fa-info-circle"> </span>
    <kendo-tooltip name="PersonInfo" position="bottom" width="300" height="300" content-handler="GetPersonData" content-template-id="PersonTooltipTemplate"></kendo-tooltip>
</div>

 

JS

 

function GetPersonData(e)
{
    var personId = document.getElementById("hidPersonId").value;
 
    $.ajax(
        {
            async: true,
            url: "",
            data: { id: personId },
            contentType: "application/json",
            success: function (data)
            {
                return data;   //{ EmployeeId: "12345" }
            },
            error: function (errorThrown)
            {
                console.log("bad");
                console.log(errorThrown);
            }
        });
}
<script type="text/x-kendo-template" id="PersonTooltipTemplate">
    <div class="d-flex">
        <div class="col-12 col-md-4 col-lg-4 col-xl-4 order-0">
            <label class="control-label">Employee Id</label>
        </div>
        <div class="col-12 col-md-4 col-lg-4 col-xl-4 order-1">
            #= data.EmployeeId #
        </div>
    </div>
</script>
Veselin Tsvetanov
Telerik team
 answered on 17 Jan 2020
4 answers
184 views

I used your theme builder which... thank you.  These things are complicated.

Theme Builder Link

I love what it gave me except for the busy indicators.  I swear, I thought I was being punked the first time I saw this.  These are horrendous.  Prior to discovering the theme builder, I was going just without anything from the theme builder and I had one large circular motion busy indicator.  That was awesome. 

How do I get back there?  Can you tell me how to use my theme except go back to the previous busy indicator? 

To create my theme, I picked the bootstrap v3 theme and change some colors... then downloaded it.  The builder itself doesn't let you see the busy indicator on the grid so you have to use the theme to see what it provides.

Thanks for your help,

Joel

Alex Hajigeorgieva
Telerik team
 answered on 15 Jan 2020
2 answers
297 views
Can't find this in the documentation anywhere. Is it possible? 
Martin
Telerik team
 answered on 14 Jan 2020
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?