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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Re-set the column layout after initialization

Thread ID:

Created:

Updated:

Platform:

Replies:

142914 Feb 25,2019 10:06 PM UTC Feb 28,2019 04:24 AM UTC JavaScript - EJ 2 3
loading
Tags: Grid
Jessica DeBlois
Asked On February 25, 2019 10:06 PM UTC

Hi, 
We save the settings of the grid externally and I need to completely reorganize the columns in the grid after it has been rendered. By that, I mean that I have to change the order, the width and the visibility of many columns, and I don't know in advance which it will be. The user can change the configuration of the grid at any moment. I try to just put the new columns in the grid 'column' member. It changes the display correctly, but the columnMenu and the drag and drop grouping stops working.

Let's says I have this grid:
let grid: Grid = new Grid({
    dataSource: data,
    columns: [
                { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, type: 'number' },
                { field: 'CustomerID', width: 140, headerText: 'Customer ID', type: 'string' },
                { field: 'Freight', headerText: 'Freight', textAlign: 'Right', width: 120, format: 'C' },
                { field: 'OrderDate', headerText: 'Order Date', width: 140, format: 'yMd' }
    ],
    allowPaging: true,
    allowReordering: true,
    allowGrouping: true,
    allowSorting: true,
    pageSettings: { pageSize: 7 }
});

And I want to change the columns to this:
let newColumns = [
     { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, type: 'number' },
     { field: 'OrderDate', headerText: 'Order Date', width: 80, format: 'yMd' }
     { field: 'Freight', headerText: 'Freight', textAlign: 'Right', width: 200, format: 'C' },
     { field: 'CustomerID', width: 70, headerText: 'Customer ID', type: 'string', visible: false },
];

I tried to do:
grid.columns = newColumns;
but the sorting, the columnMenu and the drag and drop grouping stops working.

How would I do that without having to destroy the grid and keep the functionalities of the grid?

Thanks!

Thavasianand Sankaranarayanan [Syncfusion]
Replied On February 27, 2019 08:56 AM UTC

Hi Jessica, 
 
Greetings from Syncfusion. 
 
Query: I try to just put the new columns in the grid 'column' member. It changes the display correctly, but the columnMenu and the drag and drop grouping stops working. I tried to do: grid.columns = newColumns; but the sorting, the columnMenu and the drag and drop grouping stops working. How would I do that without having to destroy the grid and keep the functionalities of the grid? 
 
We have validated your query and we have checked the reported problem at our end. It works fine. Here, we have prepared a sample based on your code snippets. We have changed the grid columns dynamically by using button click. Grid functionalities like sorting, grouping and column menu are working fine. Please find the below code example and sample for your reference. 
 
[code example] 
... 
import { Grid, Selection, Page, Reorder, Group, Sort, ColumnMenu } from '@syncfusion/ej2-grids'; 
... 
 
Grid.Inject(Selection, Page, Reorder, Group, Sort, ColumnMenu); 
 
/** 
* Default Grid sample 
*/ 
 
     
    let data: Object = new DataManager(orderData as JSON[]).executeLocal(new Query().take(15)); 
    let grid: Grid = new Grid({ 
    dataSource: data, 
    columns: [ 
                { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, type: 'number' }, 
                { field: 'CustomerID', width: 140, headerText: 'Customer ID', type: 'string' }, 
                { field: 'Freight', headerText: 'Freight', textAlign: 'Right', width: 120, format: 'C' }, 
                { field: 'OrderDate', headerText: 'Order Date', width: 140, format: 'yMd' } 
    ], 
    allowPaging: true, 
    allowReordering: true, 
    allowGrouping: true, 
    allowSorting: true, 
    pageSettings: { pageSize: 7 }, 
    showColumnMenu: true, 
}); 
 
let newColumns = [ 
     { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, type: 'number' }, 
     { field: 'OrderDate', headerText: 'Order Date', width: 80, format: 'yMd' }, 
     { field: 'Freight', headerText: 'Freight', textAlign: 'Right', width: 200, format: 'C' }, 
     { field: 'CustomerID', width: 70, headerText: 'Customer ID', type: 'string', visible: false }, 
]; 
grid.appendTo('#Grid'); 
 
let chngBut: Button = new Button({ cssClass: 'e-flat'},'#change'); 
 
document.getElementById('change').onclick = () => { 
  (grid as any).columns = newColumns;      //change  
} 
 
 
 
Please get back to us if you need further assistance. 
 
Regards,
Thavasianand S. 


Jessica DeBlois
Replied On February 27, 2019 10:52 PM UTC

Hi,
My bad, I was deleting the prototypes of the columns when applying the new ones. So the grid was not able to use the methods afterward.

Thanks for the help!

Thavasianand Sankaranarayanan [Syncfusion]
Replied On February 28, 2019 04:24 AM UTC

Hi Jessica, 
 
We are happy that the problem has been solved. 
 
Please get back to us if you need any further assistance.  
                          
Regards, 
Thavasianand S.

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

;