Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set programatically the selected Row? #381

Closed
HaythemJ opened this issue Aug 16, 2015 · 10 comments
Closed

How to set programatically the selected Row? #381

HaythemJ opened this issue Aug 16, 2015 · 10 comments

Comments

@HaythemJ
Copy link

Hi,

I have an angular grid and a form. Each time I select a row, I amke changes and I save and refresh data. Everything looks good unless I need to keep my row selected since this is not appropriate for the end user.

Best Regards
HJ

@ceolter
Copy link
Contributor

ceolter commented Aug 16, 2015

Please see the selection methods in the API:
http://www.angulargrid.com/angular-grid-api/index.php

@ceolter ceolter closed this as completed Aug 16, 2015
@HaythemJ
Copy link
Author

Many thanks for your support, it was there in the documentation, I did not scroll down:

$scope.gridOptions.api.forEachInMemory( function (node) {
        if (node.data.country === 'United States') {
            $scope.gridOptions.api.selectNode(node, true);
        }
    });

@rboughani
Copy link

i try to set set the value of selected row to Angularjs variable, it shown good in console, but in html page, i have undefined,
have you any idea please !

@safeerk
Copy link

safeerk commented Oct 13, 2016

This one is fine , this works fine if its a straight grid,.. But if its a Tree view structure .. is there any way we can point out the selected node...

@rrazong
Copy link

rrazong commented Nov 17, 2016

Just updating the link to the API's selection methods:
https://www.ag-grid.com/javascript-grid-selection/
See the "Node Selection API" section.

@harsh5400
Copy link

I tried node selection it is working but scroll down is not working

Please help us

@gregbown
Copy link

gregbown commented Feb 26, 2017

The grid selection documentation does not describe how to search for a row based on a known field value. Just in case anyone needs it. The node selection API documentation does not list setExpanded.

          this.gridOptions.api.forEachNode( (node) => {
            if ( node.data.user_name === this.searchResults.user_name ) {
              // Master open detail.  You could also call node.setSelected( true ); for alternate design.
              node.setExpanded(true);
            }
          });

@chat-du-cheshire
Copy link

Hi, does anyone knows can I select row silently? I mean without emiting rowSelected event.

@PWDrew
Copy link

PWDrew commented Nov 25, 2019

setSelected has a third argument, suppressFinishActions, that unhelpfully is not mentioned in the API docs. If you set this to true, it will not issue callbacks after AG grid has handled selection.

So you can do

    event.api.forEachNode((node: any) => {
      const nodeIsSelected = setOfSelectedNodes.has(node.data.path);      
      if (node.isSelected() !== nodeIsSelected) {
        node.setSelected(nodeIsSelected, false, true);
      }
    });

@caglarsarikaya
Copy link

aggrid on ready function is not proper for this transact. agon ready just drawing table if you want manipulate data you have to approach before ag ready. but there is no option for this.if you add this code on your methods.

getProducts: async function() {
      let data = await repository.getAll("Product").then(r => r.list);
      for (let i = 0; i < this.value.length; i++) {
        for (let j = 0; j < data.length; j++) {
          if (this.value[i].productId == data[j].productId) {
            let x = data.splice(j, 1)[0];
            data.unshift(x);
            break;
          }
        }
      }
      this.productDataForAggrid = data;
      this.gridApi.setRowData(this.productDataForAggrid);
      window.watcher = setInterval(this.setSelectedItems, 50, this.gridApi);
    }

this function is normal get method except last part. İf you selected some rows on ag and if you close ag all selection will deleted on the table but you stıll have which data selected on your data property when you openin ag again. You will fallow this way.this part of code for real ready function i mean before preparation of data.

setSelectedItems(api) {
      if (this.productDataForAggrid.length == api.getDisplayedRowCount()) {
        for (let i = 0; i < this.value.length; i++) {
          let node = api.getRowNode(this.value[i].productId.toString());
          if (node) {
            node.setSelected(true);
          }
        }
        this.gridApi.sizeColumnsToFit();
        clearInterval(window.watcher);
        window.watcher = 0;
        //console.log("ready!");
      }
    }

firstly we will add all selected data on value prop for adding to billing list. But if customer wants to reopen product select aggrid again customer cant see the selected products. This getproducts func work for everytime on ag open. and getting all products. compare this data with our value property. and sending to setSelectedItems funciton for check selected.


 saveSelectedProducts() {
      this.value.splice(0, this.value.length);
      for (var i = 0; i < this.gridOptions.api.getSelectedRows().length; i++) {
        if (this.gridOptions.api.getSelectedRows()[i].sellPrice === undefined)
          this.gridOptions.api.getSelectedRows()[
            i
          ].sellPrice = this.gridOptions.api.getSelectedRows()[i].odooId;

        if (this.gridOptions.api.getSelectedRows()[i].piece === undefined)
          this.gridOptions.api.getSelectedRows()[i].piece = 1;

        this.value.push(this.gridOptions.api.getSelectedRows()[i]);
      }
      //this.$emit("selectedProductsList", this.value);
      this.openProductPopup = false;
    },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants