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

Format Zero as blank

Thread ID:

Created:

Updated:

Platform:

Replies:

146790 Aug 20,2019 09:46 AM UTC Aug 22,2019 05:14 AM UTC ASP.NET Web Forms 3
loading
Tags: Grid
Bob Needham
Asked On August 20, 2019 09:46 AM UTC

Hi

could you tell me how to format a numeric column in a grid as blank if the value is zero please. i have tried various formats like below but it only seems to like
simple formats like n4, n0 etc. im sure there must be some way but i cant figure it out

               <ej:Grid ID="ClockingGrid" runat="server" Width="1100px" SelectionMode="Single"
                  OnServerCommandButtonClick="ClockingGrid_ServerCommandButtonClick"
                  AllowSorting="True" AllowPaging="True" IsResponsive="true">
                  <ClientSideEvents>
                  </ClientSideEvents>
                  <Columns>
                     <ej:Column Field ="ClockingID"   HeaderText="ID"      Width="75"  TextAlign="Right" IsPrimaryKey="True" />
                     <ej:Column Field ="Date"         HeaderText="Date"    Width="160" TextAlign="Right" Format="{0:ddd dd/MM/yy HH:mm:ss}" />
                     <ej:Column Field ="ClockingType" HeaderText="T"       Width="40"  TextAlign="Center"/>
                     <ej:Column Field ="DeviceID"     HeaderText="Dev"     Width="65"  TextAlign="Right" />
                     <ej:Column Field ="JobCode"      HeaderText="Job"     Width="75"  TextAlign="Right" Format="{0:0;;}"/>
                     <ej:Column Field ="Latitude"     HeaderText="Lat"     Width="75"  TextAlign="Right" Format="{0:n4}" />
                     <ej:Column Field ="Longitude"    HeaderText="Lon"     Width="75"  TextAlign="Right" Format="{0:n4}" />
                     <ej:Column Field ="Accuracy"     HeaderText="Acc"     Width="60"  TextAlign="Right" Format="{0:n0}" />
                     <ej:Column Field ="Address"      HeaderText="Address" Width="250" TextAlign="Left" />
                     <ej:Column HeaderText="G" TextAlign="Left" Width="37" CssClass="btncolstyle" HeaderTextAlign="Center" AllowSorting="false" >                    
                        <Command>
                           <ej:Commands Type="edit" >
                              <ButtonOptions Width="24" Height="24" ImagePosition="ImageLeft" ContentType="TextOnly"
                                             ShowRoundedCorner="true" Text="" CssClass="btngeocode">
                              </ButtonOptions>
                           </ej:Commands>
                        </Command>
                     </ej:Column>  

                     <ej:Column Field ="JobHours" HeaderText="Job Hr" Width="65" TextAlign="Right" Format="{0:n2}"/>
                     <ej:Column Field ="TAAHours" HeaderText="TAA Hr" Width="65" TextAlign="Right" Format="{0:n2}"/>
                  </Columns>
                  <PageSettings PageSize="18" />
               </ej:Grid> 


FYI: this is a simple method in my code library that i have that works for general formatting of an integer

      public static string BlankIfZero(int myInt)
      {
         return string.Format("{0:0;-0;\"\"}", myInt);
      }


thanks

Bob


Farveen Sulthana Thameeztheen Basha [Syncfusion]
Replied On August 21, 2019 09:03 AM UTC

Hi Bob, 

Thanks for contacting Syncfusion Support. 

Query#:-could you tell me how to format a numeric column in a grid as blank if the value is zero please.  
 
We have achieved your requirement through QueryCellInfo event of the Grid. Using queryCellInfo event we have changed the value using args.cell.textContent if it is zero or null.  Refer to the code example:- 

<ej:Grid ID="FlatGrid" runat="server" AllowPaging="True" AllowScrolling="True" AllowFiltering="False" AllowReordering="False" AllowSorting="True" AllowSelection="True" Selectiontype="Multiple" >  
       <ClientSideEvents QueryCellInfo="queryCellInfo" />  
           <Columns>  
                <ej:Column Field="Id" HeaderText="Order ID" Width="90"  IsPrimaryKey="True" Visible="false" />  
                <ej:Column Field="Name" HeaderText="Customer ID" Width="85"/>  
                <ej:Column Field="Freight" HeaderText="Employee ID" Format="{0:C}"  Width="70"/>  
                 
        </Columns>  
  
  </ej:Grid> 
 
       <script>  
         function queryCellInfo(args) {  
              if (args.column.field == "Freight") { 
               if (args.cell.textContent == null || args.cell.textContent == "") { 
                    var val = "$0:0"; 
                    args.cell.textContent = val; 
                } 
            } 
         }  
  
 </script>  
   

Refer to the API Link:-  

Please get back to us if you need any further assistance. 

Regards, 
Farveen sulthana T 


Bob Needham
Replied On August 21, 2019 12:06 PM UTC

Hi

your solution didn't work, it was obviously not tested, but you pointed me in the right direction, so thanks for the help.

i asked how to format a numeric column in a grid as blank if the value is zero and below is my amended solution that works great,

      function queryCellInfo(args) {
         if (args.column.field == "JobCode") {
            if (args.cell.textContent == null || args.cell.textContent == "0") {
               args.cell.textContent = "";
            }
         }
      }

regards

Bob


Farveen Sulthana Thameeztheen Basha [Syncfusion]
Replied On August 22, 2019 05:14 AM UTC

Hi Bob, 

Thanks for your update. Please get back to us if you need any further assistance. 

Regards, 
Farveen sulthana T 


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