Question about the working of the CrmExtWeb

Nov 10, 2008 at 10:14 AM
Edited Nov 10, 2008 at 12:10 PM
Hi,

First of all this is really great code. It has the same look & feel as the "GridControls" of CRM4.0. But I still have some questions about how you have to do some things. I couldn't find a tutorial explaining how your custom "GridControl" works.

1. How can you loop trough your "Grid", knowing which rows the user has selected (by checking the checkbox)? Do you have to do this with javascript?
2. Is there a way to put some columns hidden to give extra data -> as a GUID for ex. -> If I put the column with on 0px, I can't use the value of that column. Putting it on 1px, gives me unwanted results.
3. I would like to have the "Delete" abilitie as in "CRM 4.0" Grids. How would you do it?

As you can see there are many questions abouw how to use the GRID itself. It would be handy if you made some kind of tutorial!

Or just help me on the above issues and it would be a great help :D

Thx for the great work you've done on this one!

Kind Regards,
Frederic
Coordinator
Nov 17, 2008 at 4:20 AM
Find my answers below:
1. How can you loop trough your "Grid", knowing which rows the user has selected (by checking the checkbox)? Do you have to do this with javascript?
    Use SelectedIndices[], or SelectedItemIds[] property at server side or getSelectedItems() method at client side.
2. Is there a way to put some columns hidden to give extra data -> as a GUID for ex. -> If I put the column with on 0px, I can't use the value of that column. Putting it on 1px, gives me unwanted results.
    Set DataIdField property for Guid, and DataCodeField for Typecode before binding the DataSource. Your DataSource must contain these two fields in a data row.
3. I would like to have the "Delete" abilitie as in "CRM 4.0" Grids. How would you do it?
    Put a Delete button in the Toolbar allowing postback. At server side, use SelectedIndices[], or SelectedItemIds[] property (in case using DataIdField and DataCodeField) to know the items selected. Then delete those items using CrmSDK and rebind the grid.
Nov 20, 2008 at 9:11 AM
Edited Nov 20, 2008 at 9:38 AM

Hi,

I just tried out what you've said, but with no result. Could you give me a little example ?
In javascript I tried the following Code, he does loop trough all the selected items, but how do I get the data ?

 

Javascript Code-Snippet :

var oGridItems = document.crmGrid.getSelectedItems();

for(var oRow in oGridItems)

{

alert("Testing");

alert(oRow.itemid);

alert(oRow.itemcode);

alert(oRow.itemlabel);

}

Then you've also said I needed to set the DataIdField property for guid and the DataCodeField for TypeCode. See here below how I think It has to be done :

<edn:GridControl ID="crmGrid" runat="server" EnableViewState="false" AllowClientSideSelection="true" AutoGenerateColumns="false" DisplayStatusBar="true" OnQueryDataSource="crmGrid_QueryDataSource" OnClientRowDblClick="crmGrid_ClientRowDblClicked" DataIdField="GUID" DataCodeField="TypeCode"> ....

In my CS-behind code I do the following, when creating my "DataSource":

 

DataTable GetDummyDataTable(QueryDataSourceEventArgs args)

{

DataTable table = new DataTable();

table.Columns.Add(new DataColumn("GUID"));

table.Columns.Add(new DataColumn("TypeCode"));

table.Columns.Add(new DataColumn("fullname"));

table.Columns.Add(new DataColumn("emailaddress1"));

table.Columns.Add(new DataColumn("telephone1"));  

 

for (int I = 0; I < 50; I++)

{

object[] values = new object[table.Columns.Count];

for (int j = 0; j < table.Columns.Count; j++)

{

if (j == 0) values[j] = I.ToString();

if (j == 0) values[j] = I.ToString() + " Type";

else values[j] = table.Columns[j].ColumnName+"("+I+","+j+")";

}

table.Rows.Add(values);

}

 return table;

}

 Is the above way of working correct? I’m able to go trough all the “Rows” with the javascript, but it gives me an “Undefined”-error on the three alerts (except for the first “Testing” one).

Also you've said to use the "SelectedIndices[], or SelectedItemIds[] property" at server-side.  I tried the following but it gave me an error :

String IDValue = String.Empty;

String IDLabel = String.Empty;

String IDCode = String.Empty;

foreach (GridItemID ID in crmGrid.SelectedItemIds)

{

IDValue = ID.ID.ToString();

      IDLabel = ID.Label.ToString();

      IDCode = ID.Code.ToString();

      //GetNeededInfo(IDValue, IDLabel, IDCode);

}

 

It gave me an “IndexOutOfRangeException was unhandled by user code”, Index is out of matrix boundries.

The following is giving errors :

 

      public GridItemID[] SelectedItemIds

      {

            get

            {

                  int[] selectedIndices = this.SelectedIndices;

                  GridItemID[] itemIds = new GridItemID[selectedIndices.Length];

                  foreach (int I in selectedIndices)

                  {

                        itemIds[I] = this._itemIds[I];

                  }

                  return itemIds;

            }

      }

 

What Am I doing wrong ? If possible, could you correct me?


Kind regards,
Frederic

Apr 27, 2009 at 7:12 PM

Frederic,
Here is an example of setting the DataIdField and DataCodeField:

crmGrid.DataIdField = "activityid";
crmGrid.DataCodeField =
"activitytypecode";

The gridInner_ItemCreated method will use these properties and set them as attributes of each row at runtime as shown here:
<tr class="mscrm-GridControl-Row" itemid="6938dfcd-8333-db11-8626-00065b8d00b4" itemcode="campaignresponse" ondblclick="crmGrid_ClientRowDblClicked(doSingleSelect('crmGrid_hdnControlStyles','crmGrid_pnlGridArea','crmGrid_headerTable','crmGrid_hdnSelectedIndices','crmGrid_pnlSelectInfo', false))" onclick="doSingleSelect('crmGrid_hdnControlStyles','crmGrid_pnlGridArea','crmGrid_headerTable','crmGrid_hdnSelectedIndices','crmGrid_pnlSelectInfo', true)" style="white-space:nowrap;">

Then you can reference this id field with client side javascript like this:

function crmGrid_ClientRowDblClicked(oRow)
{
    alert(oRow.itemid + " Selected");
}

 

Mar 9, 2010 at 10:10 AM

Hello guys,

first i wanna say thanks for sharing this code 

but there's something that isn't really clear for me about how to attach the client id,

when i use

crmGrid.DataIdField="Contactid";  i get itemid=crmsdk.key and not xxxxxxxx-xxxxxxxxxxxxxx-xxxxxxxx-xxxxxxxxxx

Frederic have u tried the code listed by cmerrill ?

if so please can u tell me where to write 

crmGrid.DataIdField = "activityid";
crmGrid.DataCodeField = 
"activitytypecode";

Thank you