Dynamically select columns in the New Revised Grid Control (V4.3.1) - Forum - Rollbase - Progress Community

Dynamically select columns in the New Revised Grid Control (V4.3.1)

 Forum

Dynamically select columns in the New Revised Grid Control (V4.3.1)

This question is answered

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

Verified Answer
  • 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.

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

    rbf_getGridControlComponent(0).getKendoConfig().resize();
All Replies
  • 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.

    Regards,
    Siraj.
  • 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

  • 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.

  • 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]

  • What happens if you do the following:

    rbf_getGridControlComponent(0).getKendoConfig().dataSource.read();
  • My rows are cleared.

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

    You should check this link:

    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);
  • Hello Ruben,

    Thanks for the suggestions.

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

    --

    Charles.

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

    rbf_getGridControlComponent(0).getKendoConfig().resize();
  • Hello Ruben,

    Yes, that works well.

    Thanks

    --

    Charles.