Clear selection in FlexGrid

Posted by: jon-andersen on 14 September 2017, 11:12 am EST

    • Post Options:
    • Link

    Posted 14 September 2017, 11:12 am EST

    Hi

    Is it possible to remove all selection programmatically from the FlexGrid?

    More specific, when I load my contents into the FlexGrid, it has the first row selected by default. I would rather the grid had NO selected rows initially…

    Thanks!

    Jon

  • Posted 14 September 2017, 11:12 am EST

    Hi Jon

    Sure. There’s two easy ways to do this:

    1. You can tell the FlexGrid to select an invalid cell (like -1,-1):

      flex.select(-1,-1);

    2. Or you can move the CollectionView cursor to position -1:

      // expose data as a CollectionView to get events

      $scope.data = new wijmo.collections.CollectionView(data);

      $scope.data.moveCurrentToPosition(-1);

  • Posted 14 September 2017, 11:12 am EST

    Hi!

    Excellent! That did the trick!

    Thanks!

    Jon

  • Posted 14 September 2017, 11:12 am EST

    Hi

    I’m searching for a way to clear grid solution and I found this topic.

    I did what Bernado said and it worked. The selection’s cleared.

    But the selectionChanged event is not fired.

    I try to fire the event myself but it’s not working

    [js] grid.select(-1, -1);

    var range = new wijmo.grid.CellRange();

    var eventArgs = new wijmo.grid.CellRangeEventArgs(grid,range)

    grid.onSelectionChanged(eventArgs);[/js]

    And I got this error

    [js]Assertion failed in Wijmo: function GridPanel(grid, cellType, rows, cols, element) {

    this._offsetY = 0;

    this._g = wijmo.asType(grid, _grid.FlexGrid);

    this._ct = wijmo.asInt(cellType);

    this._rows = wijmo.asType(rows, _grid.RowCollection);

    this._cols = wijmo.asType(cols, _grid.ColumnCollection);

    this._e = wijmo.asType(element, HTMLElement);

    this._rng = new _grid.CellRange();

                // dispatch blur event for focused cells before recycling the panel
                if (!GridPanel._evtBlur) {
                    GridPanel._evtBlur = document.createEvent('HTMLEvents');
                    GridPanel._evtBlur.initEvent('blur', true, false);
                }
            } expected. undefined[/js]
    
  • Posted 14 September 2017, 11:12 am EST

    Hi,

    We are sorry, we are unable to replicate the issue at our end with the latest build 5.20172.334. You can refer to the fiddle for the same.

    Thanks,

    Manish Kumar Gupta

  • Posted 14 September 2017, 11:12 am EST

    I also have problem clearing selection on the collection view. I tried to this.cv.moveCurrentToPosition(-1) but it show throws error saying

    angular.js:13550 ** Assertion failed in Wijmo: Number expected. undefined

    angular.js:13550 ** Assertion failed in Wijmo: Date expected. undefined

  • Posted 6 March 2020, 11:20 am EST

    i have same issue. i need somehow clear selection before initialization of grid.

    is there some property that allow load page with grid without selection first row?

    i use this code to temporary fix issue

    initGrid: function (flex, e) {
    // clear selection not wroks!
    flex.select(-1, -1);
    
    flex.selectionChanged.addHandler((s, e) => {
    	$scope.selected_data_item = $scope.data[e.row];
    		if (!$rootScope.$phase) {
    			$scope.$digest();
    		}
    	});
    
    

    and there is incorrect work of grid

    if i remove line ```

    flex.select(-1, -1);

    
    
    Thanks,
    Anatoliy.
  • Posted 9 March 2020, 1:07 am EST

    Hi Anatoliy,

    Please try to set the collectionView’s currentItem to null in this case. Please refer to the following code snippet for reference:

    
    initGrid: function (flex, e) {
      flex.collectionView.currentItem=null;
    }
    
    

    Regards,

    Manish Gupta

  • Posted 10 March 2020, 1:43 pm EST

    thanks , Manish Gupta, but flex.collectionView has “undefined” value. Is there other way to solve this issue?

    With regards,

    Anatoliy.

  • Posted 11 March 2020, 5:35 am EST

    Hi Anatoliy,

    Please refer to the sample below that shows how to remove the selection from the FlexGrid after the initial load.

    https://jsfiddle.net/yn85okjs/10/

    Regards,

    Ashwin

  • Posted 11 March 2020, 10:10 am EST

    hi Ashwin,

    ok. i see your example, and there is not issue, but you use static data. Try use not static data, but that loads from the server by ajax or replace line 28 of your code with next code and use selection-mode=“3”

    $timeout(function(){
        	$scope.data = new wijmo.collections.CollectionView(data);
        }, 2000);
    

    and you will see the issue.

    https://jsfiddle.net/c8m5bozk/

    Thanks,

    Anatoliy.

  • Posted 12 March 2020, 1:54 am EST

    Hi Anatoliy,

    If the data is returned using an AJAX call, then simply set the currentItem to null in the success callback after assigning the data. In the sample above, when the data is assigned after setTimeout, I updated the currentItem to null.

    https://jsfiddle.net/31ea8nsk/1/

    ~regards

  • Posted 12 March 2020, 5:30 am EST

    Thanks, Ashwin!

    But i think you need create new attribute for grid , something like “clearSelection” in next version of grid to eliminate this issue forever, Or do not select items at all, let users select items like they want manually.

    Best regards,

    Anatoliy.

  • Posted 12 March 2020, 11:38 pm EST

    Hi Anatoliy,

    There is a selectionMode property that you can use in your case. This property is used to determine how cells can be selected in the FlexGrid. It takes an enum value of wijmo.grid.SelectionMode:

    https://www.grapecity.com/wijmo/api/enums/wijmo_grid.selectionmode.html

    You can set its value to ‘None’ while defining the grid and when the grid is initialized, you can set it back to ‘CellRange’. Then, whenever the data will be set, no cell will be selected.

    https://jsfiddle.net/1eftc7j6/1/

    ~regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels