Boolean false field values are not sent as Patch delta

Hello,
I use SfGrid for crud operations with ODataV4 api. But boolean fields cannot be made false by grid edit dialog in database.
To show the issue i made a test application and attached it with some images showing "Updated Properties" (properties sent to api Patch action as Delta). For the ease of setup InMemoryDatabase is used. The program has a simple model:

   
    public class Employee
    {
        [Key]
        public Guid Id { get; set; }

        //[Required]
        [StringLength(50)]
        public string Name { get; set; }
        
        public bool Retired { get; set; }
    }

And the Index.razor page with SfGrid is:

@page "/"

<SfGrid @ref="Grid" TValue="Employee" Toolbar="@(new List<string>() { "Add" })" AllowFiltering="true" AllowGrouping="true" AllowReordering="true" AllowResizing="true" AllowSorting="true" ShowColumnChooser="true" ShowColumnMenu="true">
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" ShowDeleteConfirmDialog="true" Mode="EditMode.Dialog"></GridEditSettings>
    <GridGroupSettings></GridGroupSettings>
    <SfDataManager Url="odata/employees" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>
    <GridColumns>
        <GridColumn AllowSorting="false" TextAlign="TextAlign.Center" Width="125">
            <HeaderTemplate>
                <a class="oi oi-plus" @onclick="@((ea) => Grid.AddRecord())"></a>
            </HeaderTemplate>
            <ChildContent>
                <GridCommandColumns>
                    <GridCommandColumn Type="CommandButtonType.Edit" ButtonOption="@(new CommandButtonOptions() {IconCss="e-icons e-edit", CssClass="e-flat" })"></GridCommandColumn>
                    <GridCommandColumn Type="CommandButtonType.Delete" ButtonOption="@(new CommandButtonOptions() {IconCss="e-icons e-delete", CssClass="e-flat" })"></GridCommandColumn>
                </GridCommandColumns>
            </ChildContent>
        </GridColumn>
        <GridColumn Field=@nameof(Employee.Id) IsPrimaryKey="true" IsIdentity="true" Visible="false" ShowInColumnChooser="false" ShowColumnMenu="false"></GridColumn>
        <GridColumn Field=@nameof(Employee.Name) HeaderText="Name" Width="250"></GridColumn>
        <GridColumn Field=@nameof(Employee.Retired) HeaderText="Retired" DisplayAsCheckBox="true" Width="100"></GridColumn>
    </GridColumns>
</SfGrid>

@code {
    public SfGrid<Employee> Grid;

}


If a field with boolean type displayed as checkbox (DisplayAsCheckBox="true") is edited and its value is made false in Edit Dialog the new value (false) is not sent to server.

To check if the problem is with OData Api i tested it with Postman and sent a Patch request with Retired field set to false and it updated successfuly.

If Patch request is problematic with OData and gird, how can we send Put request instead of Patch?


Attachment: TestApp_df81a609.zip

6 Replies

AA ali arslan April 4, 2021 02:25 PM UTC

Hi,
I found a similar thread
 that has been solved by specifying the DefaultValue Attribute as null for boolean field. This solves my problem too. But it does not seem an intuitive solution. What will happen if a field is Nullable (bool?)? Then it won't be possible to set the field value to null because Patch delta entity won't have boolean null value among changed properties.

For my first Blazor application i am trying to change a wpf application to web and because of OData 4 support i have decided to  try Syncfusion Blazor. I have 100+ tables in my database and i am still struggling for the first table crud operations page. Now my problem is with Grouping, the field in group cannot be edited (its readonly - disabled). Yes, removing group solves the problem, but if is a program that is used  by others it wpn't be very nice to tell the user to remove grouping then he/she can edit the field. Why at the first place a grouped field should be readonly? Its not intuitive again.

For me the most important component is Datagrid, and there are other things that are not intuitive for me in SfGrid. For a general case the grid filter template should be ready as soon as defining data type for the field, for example a bolean column should have a TriState checkbox filter template by default, a datetime column should have a datetime edit in filter template without any coding.

As an example for a boollean column the following filter template should be default:




(here Grid is a reference for parent Grid - parent grid should be reachable without defining any reference)

(It seems that code snippets  are not saved as is, so i inserted an image)

Component user should not define the same template (that must be default) whenever he/she has a column with a boolean type or DateTime type.

I suggest making GridColumn components for different datatypes and defining edit and filter templates that are suitable for the datatype by default. For example above GrdiColumn definition can be made SfCheckBoxGridColumn component derived from GridColumn. That way component users won't write too much handshaking code to bind a simple boolean column. Filter templates and edit templates should be a need for only special cases. not for usual.

And, i want to show record count in server with applied filter, which is the count returned by OData query, AggregateTemplateContext count value does not work as expected. How can i get record count in server with applied filter?

And, i use EditMode.Dialog for editing, it looks like it works fine for default text fields, but if i change column edit template then Default Edit Dialog clears header for the field and adding a Header Template has no effect on Edit Dialog header (sitil empty header). For now the solution is custom edit dialog template.


Thanks.




RS Renjith Singh Rajendran Syncfusion Team April 8, 2021 12:19 PM UTC

Hi Ali, 

Greetings from Syncfusion support. 

Query 1 : What will happen if a field is Nullable (bool?)? Then it won't be possible to set the field value to null because Patch delta entity won't have boolean null value among changed properties. 
We would like to inform you that, patch data has to be serialized to remove property with default value, in such case serializer removes bool data as its default value is false. This is a limitation. So in these scenario, to avoid this we need to set the DefaultValue attribute as informed in 163328.  

Query 2 : Now my problem is with Grouping, the field in group cannot be edited. Why at the first place a grouped field should be readonly? 
We have confirmed it as a bug and logged the defect report “Grouped column field is disabled in the Grid's edit form dialog” for the same. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle) and including the defect fix in our weekly release which is expected to be rolled out by the mid of May, 2021.  
       
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.       

Query 3 : Component user should not define the same template 
At these cases, it is suggested to use Edit/Filter Templates to customize the GridColumn’s actions based on your requirement. For better code reusability, we suggest you to define the FilterTemplate codes in a separate component in your application. We have also prepared a sample for your reference, please download the sample from the link below, 
Note : We have defined dummy data in the above sample to explain the solution of queries. The suggestions for the Query 4 and Query 5 are also included in the above sample. 

Please refer the codes below, 

 
<GridColumn Field=@nameof(Employee.Retired) HeaderText="Retired" DisplayAsCheckBox="true" Width="100"> 
    <FilterTemplate> 
        <SfCheckBoxGridColumn ContextValue="@context"></SfCheckBoxGridColumn> 
    </FilterTemplate> 
</GridColumn> 

[SfCheckBoxGridColumn.razor] 
<SfCheckBox ... ></SfCheckBox> @code {    [Parameter]    public object ContextValue { getset; }    [CascadingParameter]    public SfGrid<Employee> Grid { getset; }}

Query 4 : How can i get record count in server with applied filter? 
We suggest you to fetch the filtered records using GetFilteredRecords method of Grid. You can take count from this result and display the filtered records count value. Please refer the codes below, 

<div>Record Count after filter : @FilteredDataCount</div><GridEvents OnActionComplete="OnActionComplete" TValue="Employee"></GridEvents>public async Task OnActionComplete(ActionEventArgs<Employee> args){    if (args.RequestType.Equals(Action.Filtering))    {        var a = await Grid.GetFilteredRecords();        FilteredDataCount = JsonConvert.DeserializeObject<List<Employee>>(JsonConvert.SerializeObject(a)).Count();    }}

Query 5 : but if i change column edit template then Default Edit Dialog clears header for the field 
When using EditTemplate for a GridColumn, then the entire column information display for the corresponding column in grid edit form can be customized. So you need to set the Label for the corresponding component based on your requirement. Please refer the codes below in which we have used the FloatLabelType and Placeholder property of SfTextBox component to display the Label. 

<GridColumn Field=@nameof(Employee.Name) HeaderText="Name" Width="250">    <EditTemplate>        <SfTextBox @bind-Value="((context as Employee).Name)" FloatLabelType="FloatLabelType.Always" Placeholder="Name"></SfTextBox>    </EditTemplate></GridColumn>

Please get back to us if you need further assistance. 

Regards, 
Renjith R 



AA ali arslan April 8, 2021 07:59 PM UTC

Hello Renjith,
Thank you very much for your reply.

I think that when Virtualization or Paging is enabled and OfflineMode is disabled GridAggregates (count, average, sum ...)  should return what is in database according to the current filter.

Thanks.

Regards.
Ali A.


VN Vignesh Natarajan Syncfusion Team April 9, 2021 10:43 AM UTC

Hi Ali,  
 
Thanks for the update.  
 
Query: “ think that when Virtualization or Paging is enabled and OfflineMode is disabled GridAggregates (count, average, sum ...)  should return what is in database according to the current filter. 
 
We have analyzed your query and we understand that you are difficulties in GridAggreagtes. But we are quite unclear about your requirement. So kindly share the following details.  
 
  1. Do you want to display the Grid aggregates based on the Current view data (current page details)?
  2. Are you facing trouble in displaying aggregates based on the filtered data?
  3. Or do you want to display aggregates based on entire datasource in Grid?
  4. Share pictorial representation of your requirement.
  5. Share more details about your requirement.
 
Above requested details will be very helpful for us to validate the reported query at our end and provide solution as early as possible.  
 
Regards, 
Vignesh Natarajan 



AA ali arslan April 9, 2021 12:53 PM UTC

Hello Vignesh,
Thanks for reply.

I use OData Api for data source, and grid virtualization is enabled.. This means it does not important how many records are downloaded for current view, since user uses vertical scrollbar to see as many records as he/she wishes, so the user has the impression that he has all the records in database in current view, so he/she should be able to see the summary items (count, sum, etc.) as true values in database with his/her current filter (if any).

In the following view where virtualization is enabled it shows 20 as count of records, but in real there are 75 records in server database.


           <GridAggregates>
                <GridAggregate>
                    <GridAggregateColumns>
                        <GridAggregateColumn Field=@nameof(Form.CanDealersSee) Type="AggregateType.Count" Format="N0">
                            <FooterTemplate>
                                @{
                                    var countvalue = (context as AggregateTemplateContext);
                                    <div>
                                        <p>Count: @countvalue.Count</p>
                                    </div>
                                }
                            </FooterTemplate>
                        </GridAggregateColumn>
                    </GridAggregateColumns>
                </GridAggregate>
            </GridAggregates>


For crud applications it is better to show summary items according to server database. I think in that case the grid will be a better component, But if most developers want to see the downloaded record summaries its ok for me too, i can go with it.

Thanks

Regards
Ali A.



RS Renjith Singh Rajendran Syncfusion Team April 15, 2021 08:51 AM UTC

Hi Ali, 

Query : I use OData Api for data source, and grid virtualization is enabled.. it is better to show summary items according to server database 
We would like to inform you that it is not feasible to implement fetching aggregate value based on entire data when using OData service as remote data.  

Please get back to us if you need further assistance. 

Regards, 
Renjith R 


Loader.
Up arrow icon