Programming, technology, and CRM – from a Belgian programmer exiled to Missouri
  • rss
  • Home
  • Contact Me
  • Welcome

SlxGridHelper – Make the SlxDataGrid more convenient in our custom smart parts

Nicolas Galler | May 22, 2009

There are a few things that I like to set on all my datagrids (double-click edit, single-click select, delete/add button). In an earlier post I had described how to tweak the quickform template so that every quickform containing a grid would receive these changes.  However there were a number of drawbacks to that approach, starting with the fact that it was rather tedious to implement and affected “stock” grids negatively.  I also found out that the limit of quickforms were very easy to hit and therefore ended up doing custom smartparts in most cases.  Therefore I decided to group this functionality in an external control that would be included on the custom smart part and modify the grid’s behavior using its public API.

The general principle is the same as the one used in the previous approach, but with the increased flexibility I wanted to implement the following features:

  • Ability to specify Add/Delete buttons, using control ids pointing to other objects in the form
  • Ability to have a grid’s title bar generated, optionally including Add/Delete buttons (useful when there are several grids on a form, or a grid and some other controls)
  • Optionally specify the databinding and parent/child relationship, so as to avoid having to put the datasource code on the smartpart itself (the code to bind a Saleslogix datagrid is rather noisy and not too pretty to look at)

The code for a typical grid… with an automatically generated toolbar:

<SSS:SlxGridHelper ID="grdSalesEntitiesHelper" runat="server" GridId="grdSalesEntities"
    GridTitle="Sales Entities" ShowAddButton="true" ShowDeleteButton="true" AutoBind="true">
    <DialogSpecs ActiveSmartPartID="SEOppSalesCreditForm" CenterDialog="true"
     DialogHeight="300" DialogWidth="600" Title="Edit Sales Entity">
        <MyChildInsertInfo ChildEntityTypeName="Sage.Entity.Interfaces.ISEOppSalesCredit, Sage.Entity.Interfaces"
             ParentEntityTypeName="Sage.Entity.Interfaces.IOpportunity, Sage.Entity.Interfaces"
             ParentReferencePropertyName="Opportunity"
             ParentsCollectionPropertyName="SEOppSalesCredits" />
    </DialogSpecs>
</SSS:SlxGridHelper>
<SalesLogix:SlxGridView runat="server" ID="grdSalesEntities" GridLines="None"
AutoGenerateColumns="false" CellPadding="4" CssClass="datagrid" PagerStyle-CssClass="gridPager"
AlternatingRowStyle-CssClass="rowdk" RowStyle-CssClass="rowlt" SelectedRowStyle-CssClass="rowSelected" ShowEmptyTable="true" EnableViewState="false"
 ExpandableRows="True" ResizableColumns="True"  >
<Columns>
  <asp:ButtonField CommandName="Edit" DataTextField="SalesmanName" HeaderText="Salesman Name" />
  <asp:BoundField DataField="Adder" HeaderText="Adder"/>
  <asp:TemplateField HeaderText="Percentage">
  <ItemTemplate>
    <asp:Label runat="server" Text='<%# Bind("Percent", "{0:##%}") %>' ID="lblPercent" />
  </ItemTemplate>
  </asp:TemplateField>
  <asp:BoundField DataField="Title" HeaderText="Title" />
 </Columns>
</SalesLogix:SlxGridView>

And for a grid that is included on a tab (using the built-in toolbar – notice the “DeleteButtonId” and “AddButtonId”):

<SSS:SlxGridHelper ID="grdHelper" runat="server" GridId="grdLDC"
    AddButtonId="btnAdd" DeleteButtonId="btnDelete"
    GridTitle="" ShowAddButton="false" ShowDeleteButton="false" AutoBind="true">
    <DialogSpecs ActiveSmartPartID="SEOppLdcForm" CenterDialog="true"
     DialogHeight="300" DialogWidth="600" Title="Edit LDC Account">
        <MyChildInsertInfo ChildEntityTypeName="Sage.Entity.Interfaces.ISEOppLDCAccount, Sage.Entity.Interfaces"
             ParentEntityTypeName="Sage.Entity.Interfaces.IOpportunity, Sage.Entity.Interfaces"
             ParentReferencePropertyName="Opportunity"
             ParentsCollectionPropertyName="SEOppLDCAccounts" />
    </DialogSpecs>
</SSS:SlxGridHelper>
<SalesLogix:SlxGridView runat="server" ID="grdLDC" GridLines="None" AllowSorting="true" AllowPaging="true"
AutoGenerateColumns="false" CellPadding="4" CssClass="datagrid" PagerStyle-CssClass="gridPager"
AlternatingRowStyle-CssClass="rowdk" RowStyle-CssClass="rowlt" SelectedRowStyle-CssClass="rowSelected" ShowEmptyTable="true" EnableViewState="false"
 ExpandableRows="True" ResizableColumns="True"  >
 <Columns>
    <asp:ButtonField CommandName="Edit" HeaderText="LDC Name" DataTextField="ProspectName" ButtonType="Link" SortExpression="ProspectName" />
    <asp:BoundField HeaderText="City" DataField="City" SortExpression="City" />
    <asp:BoundField HeaderText="State" DataField="State" SortExpression="State" />
    <asp:BoundField HeaderText="Zip" DataField="Postalcode" SortExpression="Postalcode" />
    <asp:BoundField HeaderText="Zone" DataField="Zone" SortExpression="Zone" />
 </Columns>
</SalesLogix:SlxGridView>
<SalesLogix:SmartPartToolsContainer runat="server" ID="toolbar" ToolbarLocation="right">
    <asp:ImageButton runat="server" ID="btnAdd" ImageUrl="ImageResource.axd?scope=global&type=Global_Images&key=plus_16x16"
        AlternateText="Add LDC Account Number" ToolTip="Add LDC Account Number" />
    <asp:ImageButton runat="server" ID="btnImport" ImageUrl="ImageResource.axd?scope=global&type=Global_Images&key=Import_History_16x16"
        AlternateText="Import from Spreadsheet" ToolTip="Import from Spreadsheet" />
    <asp:ImageButton runat="server" ID="btnDelete" ImageUrl="ImageResource.axd?scope=global&type=Global_Images&key=Delete_16x16"
        AlternateText="Remove LDC Account Number" ToolTip="Remove LDC Account Number"
        OnClientClick="return confirm('Are you sure you wish to delete this LDC account number?');" />
</SalesLogix:SmartPartToolsContainer>

 

There is no associated code-behind in either case (of course, if I wanted to customize the databinding, I would need to do that in the code behind).

The result looks like this (this is a grid with a “generated” toolbar):

AddlDetails

The code is simple – similar to what I used before in the quickform version.  I saved a copy here if interested feel free to rummage through it and keep what you want.

Categories
Uncategorized
Comments rss
Comments rss
Trackback
Trackback

« Tips & Tricks of the Web Client Easy Business Rules with Extension Methods »

2 Responses to “SlxGridHelper – Make the SlxDataGrid more convenient in our custom smart parts”

  1. Mark Dykun says:
    May 25, 2009 at 6:41 am

    Nick, thanks, I will add this to my library of tricks.

  2. A few more resources « Trials of a New SLX Web Developer says:
    June 11, 2009 at 5:40 am

    [...] SLXGrid Helper [...]

Leave a Reply

Click here to cancel reply.

Categories

  • Experiments (4)
  • Interesting (1)
  • MSCRM (1)
  • Programming (60)
  • Rant (3)
  • Saleslogix (34)
  • Tricks (8)
  • Uncategorized (23)

Post History

  • 2010
    • January (3)
  • 2009
    • March (2)
    • April (1)
    • May (3)
    • June (3)
    • July (1)
    • September (3)
    • October (2)
    • December (5)
  • 2008
    • January (9)
    • February (4)
    • March (9)
    • April (1)
    • May (5)
    • June (8)
    • July (1)
    • August (2)
    • September (1)
    • November (1)
    • December (3)
  • 2007
    • January (3)
    • February (7)
    • March (1)
    • April (3)
    • May (6)
    • June (2)
    • July (1)
    • August (2)
    • September (5)
    • October (3)
    • November (5)
    • December (4)
  • 2006
    • January (2)
    • September (1)
    • November (3)
    • December (4)
  • 2005
    • April (1)

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox