Dynamically select columns in the New Revised Grid Control (

Posted by pcs on 01-Nov-2016 16:20

The new revised Grid Control introduced in V4.3.1 is a great improvement and provides a lot of additional functionality.

I want to dynamically control the inclusion/exclusion of columns in the grid, to allow the one grid to work in different ways depending on attribute/s of the containing object e.g. a type picklist.

Can this be done using the rbf_getGridControlComponent(gridNo) and supporting getKendoConfig() interface? Or another way?

Regards,
Peter

Posted by Thierry Ciot on 03-Nov-2016 21:05

You should be able to use the refresh function from Kendo UI widgets.  That is: gridControl.refresh();

Thierry

PS: Really glad you like the new grid control - it does make bulk editing much more functional and pleasant.

Posted by Ruben Dröge on 17-Aug-2018 13:45

After narrowing the grid, try calling the resize() method, I think that should update the scrollbar:

rbf_getGridControlComponent(0).getKendoConfig().resize();

All Replies

Posted by Mohammed Siraj on 02-Nov-2016 01:39

Hello Peter,

At the onset, thank you for your positive feedback.

GridControl fields/columns are driven by GridControl component definition. Dynamically hiding GridColumn columns is NOT a supported use-case.

However, you can still considering leveraging Client-side SDK & applying this client-side override on form pages with GridControl. This should work for all the basis cases where in the following constraints are not violated:

  • Required Field Column
  • Field ( column that is to be hidden) is used to derieve value of anything Field in GridControl eg. Dependent Picklist or Dependent Lookup

Eg: To hide second column on first grid control in the page:

function hideGridControlColumn(gridControlIndex, columnIndex) {
var gridControl = rbf_getGridControlComponent(gridControlIndex);
if (!gridControl) {
throw 'GridControl at index: ' + gridControlIndex + ' not found\n';
}
var columnCount = gridControl.getCellData().fields.length;
if (columnIndex >= 0 && columnIndex < columnCount) {
gridControl.getKendoConfig().hideColumn(columnIndex + 1);
gridControl.getCellData().fields = gridControl.getCellData().fields.filter(function (i, j) {
return j != columnIndex;
});
}
else {
throw 'Column Index invalid: ' + columnIndex;
}
}

//To hide First GridControl's second column
hideGridControlColumn(0, 1); // hideGridControlColumn(gridControlIndex, columnIndex)

Request you to try out the above utility function and see if it meets your requirements. 

Please note, the above snippet is shared only as an example and is not an in-built feature in product.

Posted by pcs on 02-Nov-2016 20:34

Hi Siraj,

Thanks for the function. Works quite well though if the original grid is wider than the page (and shows horizontal scrollbars), the grid still thinks it is as wide as the original (without the hidden columns).

Is there a refresh/resize option?

Regards,

Peter

Posted by Thierry Ciot on 03-Nov-2016 21:05

You should be able to use the refresh function from Kendo UI widgets.  That is: gridControl.refresh();

Thierry

PS: Really glad you like the new grid control - it does make bulk editing much more functional and pleasant.

Posted by Charles Ford on 16-Aug-2018 06:08

Hello,

Hiding columns works well, but I too find the Grid is the same width as the original.

When I try...

rbf_getGridControlComponent(0).refresh();

I get the error:

Uncaught Refresh not supported for GridControl component.

If I should try...

rbf_getGridControlComponent(0).getKendoConfig().refresh();

The data source appears to be cleared and I'm left with no rows

Do you have another solution to achieve a refresh/resize?

Thanks

--

Charles

[Rollbase 4.5.2.0]

Posted by Ruben Dröge on 16-Aug-2018 06:16

What happens if you do the following:

rbf_getGridControlComponent(0).getKendoConfig().dataSource.read();

Posted by Charles Ford on 16-Aug-2018 11:10

My rows are cleared.

Posted by Ruben Dröge on 17-Aug-2018 06:40

Sorry, I misunderstood your initial question (basically, how to resize the grid after removing columns).

You should check this link:

[View:https://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/Layout/auto-resize-grid-when-hiding-and-showing-columns:550:50]

So what you'll need to do is to calculate the total width of the current visible columns and that will be your new grid size.

And you'll be able to set the width of the grid (like they are doing in the example) in Rollbase using:

rbf_getGridControlComponent(0).getKendoConfig().wrapper.width(650);

Posted by Charles Ford on 17-Aug-2018 12:07

Hello Ruben,

Thanks for the suggestions.

That latest has just narrowed the grid view and left the scroll unchanged

--

Charles.

Posted by Ruben Dröge on 17-Aug-2018 13:45

After narrowing the grid, try calling the resize() method, I think that should update the scrollbar:

rbf_getGridControlComponent(0).getKendoConfig().resize();

Posted by Charles Ford on 28-Aug-2018 03:12

Hello Ruben,

Yes, that works well.

Thanks

--

Charles.

This thread is closed