gustavnavar / Grid.Blazor

Grid component with CRUD for Blazor (client-side and server-side) and ASP.NET Core MVC
GNU Lesser General Public License v2.1
696 stars 134 forks source link

SetCreateComponent does not take effect #409

Closed lpyedge closed 4 months ago

lpyedge commented 5 months ago

GridBlazor ServerSide 5.0.9

GridClient called the SetCreateComponent function, but the UI didn't update. It continues to display the standard CRUD interface.

This behavior also occurs when calling other SetXXXXComponent functions.

Additionally, the documentation appears to have an inaccuracy. The correct class name is GridUpdateComponent, not GridUpdateComponentBase.

gustavnavar commented 5 months ago

Could you send me the page where the grid is defined and the custom CRUD components?

lpyedge commented 5 months ago

Thank you for your help. Here is my code for your reference.

PaymentDestination.razor.cs

var client = new GridClient<Models.PaymentDestination>((q) => _masterDataService.GetGridRows(datas, columns, q), query, false,
     nameof(Models.PaymentDestination), columns, MasterDataRepository.LocaleCultureInfo)
     .Sortable()
     .Filterable()
     .SetStriped(true)
     .Selectable(true, true, false)
     .Crud(true, _masterDataService)
     .SetCreateComponent<PaymentDestinationCreateComponent>()
     //.SetUpdateComponent<PaymentDestinationUpdateComponent>()
     .SetHeaderCrudButtons(true);

PaymentDestinationCreateComponent.razor

@using GridBlazor
@using GridBlazor.Resources
@inherits GridCreateComponent<Models.PaymentDestination>

<h1>@Strings.Add 施行支払先</h1>
<EditForm Model="@Item" OnValidSubmit="@CreateItem">
    <DataAnnotationsValidator />
    <ValidationSummary />

    <div class="form-horizontal">
        <div class="form-group">
            <label for="FuneralCompanyId" class="control-label col-md-2">FuneralCompanyId: </label>
            <div class="col-md-5">
                <InputNumber id="FuneralCompanyId" class="form-control" readonly="readonly" @bind-Value="Item.FuneralCompanyId" />
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-5">
                <button type="submit" class="btn btn-primary btn-md">@Strings.Save</button>
                <button type="button" class="btn btn-primary btn-md" @onclick="BackButtonClicked">@Strings.Back</button>
            </div>
        </div>
    </div>
</EditForm>
lpyedge commented 5 months ago

I'm so sorry, I debugged the code again and found that it was a problem with my code. The entity class configured in the client and the entity class configured in the page component are two classes with the same name but different namespaces. The issue has been solved!

lpyedge commented 4 months ago

I'm encountering a problem when trying to reset the value of Item.FuneralCompanyId. Despite invoking StateHasChanged() after resetting the property on Item, the component doesn't reflect the new value. However, when I press the 'Save' button, the new value is rendered correctly. Is there a way to create a function to force the rendering? Additionally, changing the access modifier of IJSRuntime jSRuntime from private to protected seems beneficial for usage within a custom CRUD component.

lpyedge commented 4 months ago

I created a pull request (https://github.com/gustavnavar/Grid.Blazor/pull/411) to make the StateHasChanged() method effective in triggering component re-rendering.

gustavnavar commented 4 months ago

I've published a new package version (5.0.10) with your code modification. Thks.