question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

De-selection or changing the selection in code - not persisting

See original GitHub issue

I’m submitting a Bug report

Your Environment

| Angular 7.2.15 | Angular-Slickgrid 2.10.5| | TypeScript 3.2.4 | | Operating System: windows 8 | | NPM/Node/Yarn NPM 6.0.0 |

Context

I have the slick grid on one side of the page and a details page on the other side as the user switches selection the correct details view renders. I would like to give the user the ability to de-select by clicking on a selected row a 2nd time. I have tried all the suggestions such as angularGrid.slickGrid.setSelectedRows([]) nothing works. Even if I try to select another row through code: trying any of theses: this.angularGrid.gridService.setSelectedRows([1]); this.angularGrid.gridService.highlightRow(1); this.angularGrid.slickGrid.setActiveCell(1,1, false, false, true); doesn’t work. When I debug through it, i can see that for while both rows are highlighted (the original one and the one i’m setting in code) but than at some point the slick grid code gets rid of the new selection. None of my other methods are being hit in the interim so it’s not my code that’s causing it…

 <angular-slickgrid gridId="caseListing"
                             [columnDefinitions]="columnDefinitions"
                             [gridOptions]="gridOptions"
                             gridHeight="85vh"
                             [dataset]="dataSource"
                             (sgOnClick)="onCellClicked($event.detail.eventData, $event.detail.args)"
                             (onAngularGridCreated)="angularGridReady($event)">
 defineColumns() {
    let that = this;
    this.columnDefinitions = [
      {
        id: 'field1', name: 'field1', field: 'field1', sortable: true, minWidth: 0,
        type: FieldType.string,
        filterable: true, filter: { model: Filters.compoundInput },
        formatter: function (row, cell, value) {
          if (that.dataSource.length < 1) return '';
          return "<div class='highPriority' " + (that.dataSource[row].highPriority ? '' : 'hidden') + "><div style=\"margin-left:30%; margin-top:-85%;\">!</div></div><i class=\"fa fa-circle oval-sm\" aria-hidden=\"true\" style=\"font-size: 10px; color: " + that.dataSource[row].status.color + " \"></i> &nbsp;&nbsp;" + value;
        },

      },
      {
        id: 'field2', name: 'Field2', field: 'field2', sortable: true, minWidth: 0,
        type: FieldType.string, filterable: true, filter: { model: Filters.compoundInput }
      },
      {
        id: 'field3', name: 'Field3', field: 'field3', sortable: true, minWidth: 0,
        type: FieldType.string, filterable: true, filter: { model: Filters.compoundInput }
      }
    ];
  }

 defineOptions() {
    this.gridOptions = {
      autoResize: {
        containerId: 'demo-container'
      },
      fullWidthRows: true,
      rowHeight: 60,
      enableRowSelection: true,
      rowSelectionOptions: {
        // True (Single Selection), False (Multiple Selections)
        selectActiveRow: true
      },
      enableCellNavigation: true,
      enableColumnPicker: true,
      enableExcelCopyBuffer: true,
      enableFiltering: true,
      enableAutoResize: true,
      forceFitColumns: true,
      i18n: this.translate,
    };
  }

  //attempting to de-select a row but doesn't look like the grid allows it
  onCellClicked(arg1, arg2){
      let clickedRow = arg2.row;
      let selectedRows = this.angularGrid.gridService.getSelectedRows();
      let selectedRow = 0;
      if(selectedRows.length > 0) selectedRow = selectedRows[0];
      if(clickedRow == selectedRow){
        //the code reaches here but none of these stay selected as described above
        //this.angularGrid.gridService.setSelectedRows([]);
        //this.angularGrid.gridService.setSelectedRows([1]);
        //this.angularGrid.gridService.highlightRow(1);
        this.angularGrid.slickGrid.setActiveCell(1,1, false, false, true);
       // this.angularGrid.gridService.;
      }
      else{
        this.angularGrid.gridService.setSelectedRows([clickedRow]);
        this.setSelectedCaseId();
      }
  }

setSelectedCaseId(){
  //this will trigger a change event on the details component
    this.selectedCaseId = this.getCurrentlySelectedCaseId();
  }
  getCurrentlySelectedCaseId(){
    let obj= this.angularGrid.gridService.getSelectedRowsDataItem();
    if(obj.length > 0 && obj[0]) return obj[0].id;
    return 0;
  }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
tannenbaumscommented, Sep 17, 2019

Oh wow, this finally works in my project!!! you did it again!!! tysm

1reaction
tannenbaumscommented, Sep 16, 2019

ok not a problem. Maybe you’ll have some time at a later date…thank you so much for all your informative responses. very much appreciated!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

vscode deselect one from "change all occurrences"
On Mac, to de-select one or more substrings selected with Cmd + D , type Cmd + U . Analogously, type Ctrl +...
Read more >
Select, move, and order objects – Figma Help Center
Click and hold an object, then drag your cursor to move it. Select objects. Select objects to interact with them and change their...
Read more >
General debugging options - Visual Studio - Microsoft Learn
To set Visual Studio debugger options, select Tools > Options, and under Debugging select or deselect the boxes next to the General options....
Read more >
Multi listbox change event - selected or deselected
multi listbox like (in listbox change event): ... MsgBox "select" Else x = x - 1 MsgBox "deselect" End If. End Sub [/code]...
Read more >
How to prevent deselect previous selected annotation's object ...
here you can see i selected and annotation but when i change the tool ( “with ... How is the ie condition not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found