This is a migrated thread and some comments may be shown as answers.

CreateCellElement Event not fired on all cells displayed

14 Answers 159 Views
VirtualGrid
This is a migrated thread and some comments may be shown as answers.
Amand
Top achievements
Rank 1
Amand asked on 20 Dec 2016, 02:58 PM

Hello,

I try to use custom cells dynamically following data I want to display ( use checkbox when data is boolean). To do so I use CreateCellElement to instantiate my custom cell but it appears to this event is not fired on that specific column and the column have default display with "True" and "False" instead of check boxes. 

 

Here is a part of my code :

this._radVirtualGrid1.CreateCellElement += onGridCellTypeNeeded;
 
 
private void onGridCellTypeNeeded(object sender, VirtualGridCreateCellEventArgs e)
        {
            if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
            {
                DataType type = myDataDescriptor.getDataType(e.ColumnIndex);
                switch (type )
                {
                    case DataType.Bool:
                        e.CellElement = new CheckBoxCellElement(e.ColumnIndex);
                        registerCustomColumnIfNeeded(e.ColumnIndex);                      
                        break;
                }
            }
        }

Do you know how to fix it ?

Regards,

Amand.

14 Answers, 1 is accepted

Sort by
0
Amand
Top achievements
Rank 1
answered on 20 Dec 2016, 03:05 PM

Update :

This problem does not appears if column are the first displayed ( 1st to 9~10th) but when the column is like the 20th. If so there is still a chance that the event is fired with this specific index ( about 20% chance).

Regards,

Amand.

0
Amand
Top achievements
Rank 1
answered on 20 Dec 2016, 04:11 PM

Hello again,

I found the problem, the method RegisterCustomColumn has to be called during the grid initialization. It might force the event to be fired for these specific columns.

Regards,

Amand.

0
Hristo
Telerik team
answered on 21 Dec 2016, 09:20 AM
Hi Amand,

Thank you for writing.

Indeed, when creating custom cells one needs to also register them by calling the RegisterCustomColumn method. Additional information and an example are available here: RadVirtualGrid | Creating Custom Cells.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Amand
Top achievements
Rank 1
answered on 23 Dec 2016, 10:43 AM

Hello,

I was wondering if there is a way to invalidate custom columns in order to refresh it (e.g. I have custom column 3 and I want after an user event to unregister column 3 and register column 4) because for now I have to scroll out and scroll in in order to have the  changed display taken in account.

Regards,

Amand.

0
Hristo
Telerik team
answered on 23 Dec 2016, 03:56 PM
Hello Amand,

Thank you for writing back.

If by refreshing you mean triggering the CellValueNeeded event to fill data you can do it by calling the SynchronizeRows method of the table element: 
this.radVirtualGrid1.TableElement.SynchronizeRows(true, true);

If you want to update the layout you can call the InvalidateMeasure method again by accessing the table element and pass a true flag.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Padre
Top achievements
Rank 1
answered on 26 Dec 2016, 03:15 PM

Hello. Need help.

I have one virtual grid for two data sources.For first data source created custom cell. If set second data source in grid, then custom cell for first data source do not reload. Event CreateCellElement did not called with this column index.

0
Hristo
Telerik team
answered on 27 Dec 2016, 01:27 PM
Hi Padre,

Thank you for writing.

Data in RadVirtualGrid is populated in the CellValueNeeded event. If I understand correctly your scenario at some point you are handling the event differently to populate different data. In this respect, it would not be necessary to create the custom cell again. You can refresh the data by calling the SynchronizeRows method as per my previous reply.

The CreateCellElement is being raised during the initialization of the control or when you scroll because of the virtualization. In case you need additional assistance please open up a support ticket and send us a small sample as per your local setup.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Padre
Top achievements
Rank 1
answered on 27 Dec 2016, 02:38 PM

Hi Hristo.

This doesn't work. I have the following event handler on a button click

        private void OpenComponentList(ComponentLineType _type)
        {
            currentType = _type;

            editComponentTable  = GetEditCoponents(_type);//DataTable

            switch(_type)
            {
                case ComponentLineType.Bom:
                    EditComponentsGrid.MasterViewInfo.RegisterCustomColumn(2);
                    this.EditComponentsGrid.ColumnCount = 3;
                    break;
                case ComponentLineType.Add:
                    this.EditComponentsGrid.ColumnCount = 4;
                    break;
            }                        
            EditComponentsGrid.RowCount = editComponentTable.Rows.Count;
            if (EditComponentsGrid.RowCount == 0) 
                EditComponentsGrid.RowCount = 1;
            EditComponentsGrid.BestFitColumns();
            EditComponentsGrid.TableElement.SynchronizeRows(true, true);
        }

Event hendler for CreateCellElement
        private void CreateCellElement(object sender, VirtualGridCreateCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex < 0)
                return;
            if (currentType == ComponentLineType.Bom)
            {
                if (e.ColumnIndex == 2)
                {
                    CheckBoxCellElement CellElement = new CheckBoxCellElement();
                    e.CellElement = CellElement;
                }
            }
        }

 

Check box -is child control for cell element. May be hid him for ComponentLineType.Bom?

0
Hristo
Telerik team
answered on 28 Dec 2016, 02:53 PM
Hello Padre,

Thank you for writing.

Currently, RadVirtualGrid does not allow removing of its custom columns. We have an issue logged in our feedback portal. I have also added a vote for it on your behalf. Additionally, you can subscribe to the item and be updated with all of its status changes here: FIX. RadVirtualGrid - once a custom column is added it cannot be removed from the grid. 

The issue can be worked around by manually removing the registered custom column. In order to immediately reflect the changes in the grid you would also need to trigger a layout update of the virtualized row element. I am sending you attached a sample project demonstrating the suggested approach.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Padre
Top achievements
Rank 1
answered on 29 Dec 2016, 09:25 AM

Thank you.
I solved this problem using CellFormatting handler. 
private void VirtualGrid_CellFormatting(object sender, VirtualGridCellElementEventArgs e)
{
            if (VirtualGrid.MasterViewInfo.IsCustomColumn(e.CellElement.ColumnIndex))
            {
                RadElementCollection a = e.CellElement.Children;
                RadCheckBoxElement cb = a[0] as RadCheckBoxElement;
                if (cb != null)
                    cb.Visibility = (currentState == State.State1) ? ElementVisibility.Visible : ElementVisibility.Hidden;
            }
}

0
Hristo
Telerik team
answered on 29 Dec 2016, 10:36 AM
Hi Padre,

Thank you for writing.

I am glad that you have managed to achieve a satisfying result. Please note, however, that the custom cell will not be removed this way.

I hope this helps. Please let me know if you need further questions.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Padre
Top achievements
Rank 1
answered on 29 Dec 2016, 11:27 AM

Hi Htisto.

I will write when i find problems.

thank you for help.

 

0
Amand
Top achievements
Rank 1
answered on 02 Jan 2017, 09:29 AM

Hi Hristo,

Thank you and Padre, the workaround on the feedback portal works perfectly for my problem. Now all my columns can be Hide/Show :)

For those who want the code snap write that every time you want to refresh your display after hiding a column:

foreach (VirtualGridRowElement rowElement in    this.radVirtualGrid1.VirtualGridElement.TableElement.GetDescendants(delegate(RadElement x) { return x is VirtualGridRowElement; }, TreeTraversalMode.BreadthFirst)){  rowElement.CellContainer.Children.Clear();}

Regards,

Amand.

0
Hristo
Telerik team
answered on 02 Jan 2017, 10:19 AM
Hi Amand,

Thank you for writing.

I am glad that it is also working well in your project. Clearing the elements in the cell container object ultimately triggers the CreateCellElement which will allow full recreation of the cells for all columns.

I hope this helps. Please let me know if you need further assistance.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
VirtualGrid
Asked by
Amand
Top achievements
Rank 1
Answers by
Amand
Top achievements
Rank 1
Hristo
Telerik team
Padre
Top achievements
Rank 1
Share this question
or