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

Add Columns Programatically Before They Are Auto Generated

Thread ID:

Created:

Updated:

Platform:

Replies:

150419 Jan 6,2020 07:16 PM UTC Jan 7,2020 09:15 AM UTC Vue 1
loading
Tags: Data Grid
Marius Lian
Asked On January 6, 2020 07:16 PM UTC

Hi Syncfusion,

I could probably add columns something like this at any time:
var colObj = { headerText: "Ship City", field: "ShipCity", width: 120 };  
gObj.columns.push(colObj);
gObj.refreshColumns(); 

But I would like to add columns programatically but as early as possible. So basically add this programatically at run time:
https://www.screencast.com/t/bk3sqtImeyk

Would it be possible to add this att the data grid's loaded or created event? And if so what is the best way to add it?

Thanks,
Marius

Balaji Sekar [Syncfusion]
Replied On January 7, 2020 09:15 AM UTC

Hi Marius Lian, 
 
Greetings from Syncfusion Support. 
 
Query #1: Would it be possible to add column to Data Grid in Load or Created event ? 
 
We have analyzed your query and we can understand that you need to push columns to Grid as early as possible. Yes, you can add columns to Grid in the Load or Created events of Grid. We suggest you to use Load event. This event allows customization of Grid properties before rendering. We have achieved your requirement and created a sample based on your query. Please refer the below code snippet and sample link for more information. 
 
App.vue 
 
<template> 
  <div id="app"> 
    <ejs-grid 
      id="Grid" 
      ref="grid" 
      :dataSource="data" 
      :allowPaging="true" 
      :editSettings="editSettings" 
      :load="load" 
    ></ejs-grid> 
  </div> 
</template> 

<script> 
import Vue from "vue"; 
import { GridPlugin, Edit, Page, Toolbar } from "@syncfusion/ej2-vue-grids"; 
import { data } from "./datasource"; 

Vue.use(GridPlugin); 

export default { 
  data() { 
    return { 
      data: data, 
      editSettings: { 
        allowAdding: true, 
        allowEditing: true, 
        allowDeleting: true 
      }, 
      toolbar: ["Add", "Edit", "Delete", "Update", "Cancel"] 
    }; 
  }, 
  methods: { 
    load: function()
      var colObj = { headerText: "Ship City", field: "ShipCity", width: 120 }; 
      this.$refs.grid.ej2Instances.columns.push(colObj); 
    } 
  }, 
  provide: { 
    grid: [Page, Edit, Toolbar] 
  } 
}; 
</script> 

<style> 
</style> 
 
 
 
                                       https://ej2.syncfusion.com/documentation/api/grid/#created 
 
If we have misunderstood your query, please provide us more details that will be helpful for us to provide you better assistance. 
  1. Please share the full Grid rendering code.
 
Please get back to us if you need further assistance. 
 
Regards, 
Balaji Sekar. 


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