We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

how to set column cell value to 0 when null or empty

Thread ID:

Created:

Updated:

Platform:

Replies:

145812 Jul 9,2019 01:34 PM UTC Jul 11,2019 04:05 AM UTC ASP.NET MVC 3
loading
Tags: Grid
kalum
Asked On July 9, 2019 01:34 PM UTC

Hi,
I have a grid control with column named amount. and I need a functionality like this in that column cells. If the user do not enter a value or delete the existing value of that column cell it should always be 0. That means it should not be blank or null anytime. How do I do this. Please help.

Thank you
Kalum

Manivannan Padmanaban [Syncfusion]
Replied On July 10, 2019 06:43 AM UTC

Hi kalum, 

Thanks for contacting Syncfusion Forums. 

Query: how to set column cell value to 0 when null or empty 

From the above query, we are able to understand that you want to set the value of amount column as ‘0’ when the value is entered in that column. Using default value property we can achieve your requirement. Kindly refer the below code example, 

@(Html.EJ().Grid<Object>("FlatGrid") 
………………………………………………………… 
                .Columns(col => 
                   { 
                       col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add(); 
                       col.Field("CustomerID").HeaderText("Customer ID").Add(); 
                       col.Field("Amount").HeaderText("Amount").DefaultValue(0).Add(); 
                       col.Field("Freight").HeaderText("Freight").EditType(EditingType.NumericEdit).DefaultValue(45).Add(); 
                       col.Field("ShipCountry").HeaderText("Ship Country").DefaultValue("Brazil").Add(); 
                   })) 

Refer the below help documentation link, 

If you need further assistance please get back to us, with the complete grid code example. 

Regards, 
Manivannan Padmanaban. 



kalum
Replied On July 10, 2019 09:35 AM UTC

Hi Manivannan,
Thank you for the response. But in my case I'm using batch edit mode and looks it is not working when I delete everyting in the cell. Any help please.
Thanks
Kalum


Manivannan Padmanaban [Syncfusion]
Replied On July 11, 2019 04:05 AM UTC

Hi Kalum, 

Thanks for the update. 

Query:  But in my case I'm using batch edit mode and looks it is not working when I delete everyting in the cell. 
 
In batch edit mode, by default the value is set while adding the new record based on type. For number column, the default value 0 is set and for string column the default value empty is set. Generally in grid the type is set based on the dataSource. If you have not bound the dataSource empty then, the type for the columns are not set by default. In this case, you have to manually set the type for the column. Refer the below code example, 


@(Html.EJ().Grid<Object>("FlatGrid") 
……………………………………………… 
                    .Columns(col => 
                       { 
                           col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Type("number").Add(); 
                           col.Field("CustomerID").HeaderText("Customer ID").EditType(EditingType.StringEdit).Type("string").Add(); 
                           col.Field("Freight").HeaderText("Freight").Type("number").Add(); 
                           col.Field("ShipCountry").HeaderText("Ship Country").Type("string").Add(); 
                           col.Field("OrderDate").HeaderText("Order Date").EditType(EditingType.Datepicker).Type("date").Format("{0:MM/dd/yyyy}").Add(); 
                       })) 




And also, we want to get the default value for amount column as 0 when the value is deleted. Using before BeforeBatchSave event, we can set the value for the column when is empty while saving. Refer the below code example, 

@(Html.EJ().Grid<Object>("FlatGrid") 
……………………………………………………………………… 
                       .ClientSideEvents(e=>e.BeforeBatchSave("BeforeBatchSave")) 
                    .Columns(col => 
                       { 
………………………………………………………. 
                       })) 
 
<script> 
    function BeforeBatchSave(args) { 
        if (ej.isNullOrUndefined(args.batchChanges.added[0].Freight)) { 
            args.batchChanges.added[0].Freight = 0;  // set the value here. 
        } 
    } 
</script> 

Still facing the issue, kindly get back to us with the below details. 

  1. Share complete grid code example.
  2. Share the video demonstration of this issue.

Regards, 
Manivannan Padmanaban. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon