Monday, January 2, 2012

How to get Selected Rows of the grid Using JavaScript

Problem:
              Need to get the selected rows values using JavaScript in MS CRM 2011.

Solution:
              In my post "Retrieve rows in crm2011 subgrid with JScript" where I show you how to read all the rows of the subgrid in the Microsoft CRM 2011 using JavaScript. For this problem I will use same code but with some modification to get the rows which are selected by user. The code which is used to get the selected row detail is shown in List 1.
List 1
In the above code the only thing which is noticeable is the use of the get_selectedIds function of the grid control which will return the Ids of the selected rows, In this case the GUID of the record and then comparing the GUID with the original grid rows and if the Id is found mean row is selected and the each cell value is displayed of the selected row.


All and any comments / bugs / suggestions are welcomed!

8 comments:

Anonymous said...

Great post Asim, but i have a question. Where do you put this code in? What event?

Anonymous said...

Sorry!

This code:

document.getElementById('accountContactsGrid').control

returns NULL

I'm using FormOnload event

Asim Sajjad said...

Anonymous: you can use code where you need it mean on load of the form or even on save of form if you want to get some data from grid ?
Anonymous: Do you have same grid name as I have place mean "accountContactGrid" this grid is on account entity. In following post I have mention which name for grid is used
http://asimsajjad.blogspot.com/search/label/MS%20CRM%202011

hope that will help.

Unknown said...

Great code but i am looking money field in subgrid which i need to sum of them which was select on subgrid hows it possible?

suray kathir said...

hi all,

As i am having the same problem, i tried to use above code "var number = Number(cellValue.replace(/[^0-9\.]+/g,""));" but, var number returns NaN. so it is not working for me. then i tried the below code i written using debbuger it is working for me.

hope it is work for u guys.

var ord_totalitemamount = gridControl.getCellValue('extendedamount', ids[i]);

var numberta = ord_totalitemamount.replace(/[^0-9\.]+/g,"");
var numberrm = numberta.substring(1);
var numta = Number(numberrm);
ord_totalamount = ord_totalamount + numta;

Unknown said...

hi

how to do the same but with global grid (grid on the main crm window)

this one - var grid = document.getElementById('contentIFrame').contentDocument.getElementById('crmGrid_visualizationCompositeControl').control

Anonymous said...

I'm using this code, but IE gives me this error:

"getRecordsFromInnerGrid() isn't supported"

Anonymous said...

Case Sensitive, method name should be exactly "GetRecordsFromInnerGrid".