Exlcude certain columns from being rendered

Working on a spreadsheet display. The data that's being return is an IEnumerable. Its a parent object that has a couple classes that inherit from it. We don't always populate all the values, so we don't want to display them in the spreadsheet. Is there method we can use to build a template?.


@Html.EJS().Spreadsheet("spreadsheet").Sheets((sheet) =>
{
sheet.Ranges((ranges) =>
{
ranges.DataSource(ViewBag.TransactionReport).Add();
}).Add();
sheet.Columns(new List()).Add(); //maybe similar?
}).Render()


3 Replies 1 reply marked as answer

SP Sangeetha Priya Murugan Syncfusion Team April 21, 2022 02:11 PM UTC

Hi Andrew,


We suspect that you need to display the certain columns from the data source instead of showing all column values. And it can be achievable in our spreadsheet by using the query property. For more details regarding this requirement. Please refer the below links.


https://ej2.syncfusion.com/aspnetmvc/Spreadsheet/RemoteDataBinding#/bootstrap5


https://ej2.syncfusion.com/aspnetmvc/documentation/spreadsheet/data-binding#remote-data


Could you please check the above links and get back to us with more details like video demonstration? If we misunderstood your requirement or need any further assistance on this.


Regards,

Sangeetha M



AB Andrew Billy April 21, 2022 03:23 PM UTC

Thank you. Using this I'm able to create just the desired columns but before I go much deeper, will this work using a Viewbag property as the data source?


@using Syncfusion.EJ2

@Html.EJS().Spreadsheet("spreadsheet").SaveUrl("Save").Sheets(sheet =>
{
    sheet.Name("Report").Ranges(ranges =>
    {
        ranges.ShowFieldAsHeader(false).StartCell("A2").Query("new ej.data.Query().select(['COL1','COL2'])").DataSource(datamanager =>
        {
            datamanager.Data(ViewBag.Report);
        }).Add();
    }).Rows(row =>
    {
        row.Cells(cell=>
        {
            cell.Value("COL1").Add();
            cell.Value("COL2").Add();
        }).Add();
    }).Columns(column =>
    {
        column.Width(25).Add();
        column.Width(50).Add();
    }).Add();
}).Render()


SP Sangeetha Priya Murugan Syncfusion Team April 22, 2022 09:19 AM UTC

Hi Andrew,


Your requirement can be achievable in our spreadsheet by using query property for viewbag datasource as like as below.


Code Block:


  @Html.EJS().Spreadsheet("spreadsheet").Sheets(sheet =>

  {

      sheet.Name("Shipment Details").Ranges(ranges =>

      {

          ranges.ShowFieldAsHeader(false).StartCell("A2").Query("new ej.data.Query().select(['CustomerName', 'Model', 'PaymentMode', 'Amount']).take(200)").DataSource((IEnumerable<object>)ViewBag.DefaultData).Add();

      }).Rows(row =>

      {

          row.Cells(cell =>

          {

              cell.Value("Customer Name").Add();

              cell.Value("Model").Add();

              cell.Value("Payment Mode").Add();

              cell.Value("Amount").Add();

             

          }).Add();

      }).Columns(column =>

      {

          column.Width(100).Add();

          column.Width(130).Add();

          column.Width(100).Add();

          column.Width(220).Add();

          column.Width(150).Add();

          column.Width(180).Add();

      }).Add();

  }).Render()


For your convenience we have prepared the sample based on our suggestion. Please find the link below.


Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SpreadsheetMVC205041077


Could you please check the above link and get back to us, if you need any further assistance on this.


Regards,

Sangeetha M



Marked as answer
Loader.
Up arrow icon