- Home
- Forum
- ASP.NET Web Forms
- Format Zero as blank
Format Zero as blank
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>
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);
}
{
return string.Format("{0:0;-0;\"\"}", myInt);
}
thanks
Bob
SIGN IN To post a reply.
3 Replies
FS
Farveen Sulthana Thameeztheen Basha
Syncfusion Team
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
BN
Bob Needham
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 = "";
}
}
}
if (args.column.field == "JobCode") {
if (args.cell.textContent == null || args.cell.textContent == "0") {
args.cell.textContent = "";
}
}
}
regards
Bob
FS
Farveen Sulthana Thameeztheen Basha
Syncfusion Team
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
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
BN Bob Needham
- Aug 20, 2019 09:46 AM UTC
- Aug 22, 2019 05:14 AM UTC