Look here maybe this help You
function cellQueryInfo(args) {
var DateA = new Date(args.data.CheckOut).format("dd/MM/yyyy");
var DateC = new Date(args.data.CheckIn).format("dd/MM/yyyy");
var DateN = new Date();
var Dzis = new Date(DateN.setDate(DateN.getDate() + 0)).format("dd/MM/yyyy");//Today
var Jutro = new Date(DateN.setDate(DateN.getDate() + 1)).format("dd/MM/yyyy");//Tomorrow
var Price = args.data.TotalPrice;
if (args.column.field == "TotalPrice" && Price == 0.00) {
$($(args.cell)).css("backgroundColor", "red").css("color", "white");
}
if (args.column.field == "CheckOut" && DateA == Dzis)
$($(args.cell)).css("backgroundColor", "Yellow");
if (args.column.field == "CheckOut" && DateA == Jutro)
$($(args.cell)).css("backgroundColor", "Blue").css("color", "white");
if (args.column.field == "CheckIn" && DateC == Dzis)
$($(args.cell)).css("backgroundColor", "Green").css("color", "#ffffff");
};
<ej:Grid ID="FlatGrid" runat="server" OnServerPdfExporting="FlatGrid_ServerPdfExporting"
OnServerExcelExporting="FlatGrid_ServerExcelExporting" AllowPaging="True">
<ToolbarSettings ShowToolbar="true" ToolbarItems="excelExport,wordExport,pdfExport"></ToolbarSettings>
<Columns>
<ej:Column Field="OrderID" HeaderText="Order ID" />
.. .
. . .
<ej:Column Field="CustomerID" HeaderText="Customer ID" />
</Columns>
<ClientSideEvents QueryCellInfo="onQuery" />
</ej:Grid>
<script>
function onQuery(args) {
if (args.column.field == "CustomerID" && args.data.OrderID % 2)
$(args.cell).css("background-color", "red");
}
</script>
|
protected void FlatGrid_ServerExcelExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)
{
ExcelExport exp = new ExcelExport();
IWorkbook book = exp.Export(FlatGrid.Model, (IEnumerable)FlatGrid.DataSource, "Export.xlsx", ExcelVersion.Excel2010, true, false, "flat-lime", true);
IWorksheet worksheet = book.Worksheets[0];
//Get the index of the column
int inx = GetColIndex("CustomerID") + 1;
//Formatting applied to mentioned index values
//1- row start, inx- column start, worksheet.UsedRange.LastRow - last row in used range, 3 - column end
IConditionalFormats condition = worksheet[1, inx, worksheet.UsedRange.LastRow, inx].ConditionalFormats;
IConditionalFormat condition1 = condition.AddCondition();
condition1.FormatType = ExcelCFType.Formula;
//A1 refers to the first Column value i.e. OrderID
//We have taken mod value
condition1.FirstFormula = "=MOD($A1,2)";
condition1.BackColor = ExcelKnownColors.Red;
book.SaveAs("Export.xlsx", ExcelSaveType.SaveAsXLS, System.Web.HttpContext.Current.Response, ExcelDownloadType.Open);
}
public int GetColIndex(string field)
{
Column col = FlatGrid.Model.Columns.Find(c => c.Field == field);
var inx = FlatGrid.Model.Columns.IndexOf(col);
return inx;
} |
protected void FlatGrid_ServerPdfExporting(object sender, Syncfusion.JavaScript.Web.GridEventArgs e)
{
PdfExport exp = new PdfExport();
FlatGrid.Model.ServerPdfRowInfo = querRow;
exp.Export(FlatGrid.Model, (IEnumerable)FlatGrid.DataSource, "Export.pdf", true, true, "flat-lime");
}
public void querRow(object sender)
{
PdfGridRow row = (PdfGridRow)sender;
int inx = GetColIndex("OrderID");
if (int.Parse(row.Cells[inx].Value.ToString()) % 2 == 0)
{
int ix = GetColIndex("CustomerID");
PdfGridCellStyle pdfGridCellStyle = new PdfGridCellStyle();
row.Cells[ix].Style.BackgroundBrush = PdfBrushes.Red;
}
}
public int GetColIndex(string field)
{
Column col = FlatGrid.Model.Columns.Find(c => c.Field == field);
var inx = FlatGrid.Model.Columns.IndexOf(col);
return inx;
} |