Telerik RadGrid autopostback when row is selected - telerik-grid

I have a RadGrid with KeyboardNavigation allowed, RowSelection enabled.
When i click on a row using the mouse, the post back happens and i perform the necessary operations that i wish to do.
Now, when i use the keyboard up/down keys to change the row selection, the grid does change the SelectedRow (the display shows the selection happening). But the control does not post back in this case.
Anybody know how to create a postback after a row is changed by the keyboard?

jai telengana
function keyPress(sender, args) {
if (args.get_keyCode() == 13) {
args.set_cancel(true);
if (sender._activeRow) {
sender._activeRow.click();
}
}
}
<telerik:RadGrid ID="Manage_Group_RadGrid" AllowFilteringByColumn="true" OnItemCommand="Manage_Group_RadGrid_ItemCommand" AllowPaging="true" AllowMultiRowSelection="true" OnItemDataBound="Manage_Group_RadGrid_ItemDataBound" ShowStatusBar="true"
AllowSorting="true" OnDataBinding="Manage_Group_RadGrid_DataBinding" OnNeedDataSource="Manage_Group_RadGrid_NeedDataSource" GroupingEnabled="true" ShowGroupPanel="true" OnGroupsChanging="Manage_Group_RadGrid_GroupsChanging"
PagerStyle-AlwaysVisible="true"
PageSize="15" Height="440px"
DataKeyNames="cn" runat="server">
<EditItemStyle BackColor="green" />
<MasterTableView DataKeyNames="cn" AutoGenerateColumns="false"
PagerStyle-AlwaysVisible="true" GroupsDefaultExpanded="false" CommandItemDisplay="Top">
<Columns>
<telerik:GridBoundColumn DataField="cn" HeaderText="cn" SortExpression="cn" UniqueName="cn"
ItemStyle-Width="200px" HeaderStyle-Width="200px" />
<telerik:GridBoundColumn DataField="cn" HeaderText="sAMAccountName" SortExpression="sAMAccountName" UniqueName="sAMAccountName"
ItemStyle-Width="200px" HeaderStyle-Width="200px" />
</Columns>
<CommandItemSettings ShowAddNewRecordButton="false" />
</MasterTableView>
<GroupingSettings CaseSensitive="false" />
<GroupingSettings ShowUnGroupButton="true"></GroupingSettings>
<ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="false">
**<ClientEvents OnKeyPress="keyPress" />**
<Selecting AllowRowSelect="true" />
</ClientSettings>
</telerik:RadGrid>

Related

Why does my PXSelector ignore what I have selected

I have created a PXGraphExtension on POLandedCostDocEntry. I have added a PXAction button. When the button is pressed I show a popup panel to ask the user for a landed cost code.
The problem is that the PXSelector ignores whatever I enter into the field and resets to APPLE (or whatever Landed Cost Code is alphabetically first). If I use the Selector to choose a different code, the code I select is visible for a moment and then immediately replaced with APPLE again.
The ASPX for the popup dialog is as follows:
<px:PXSmartPanel runat="server" ID="PanelAskForLCCode" LoadOnDemand="True" AutoRepaint="True" Key="LandedCostCodeSelection" CaptionVisible="True" Caption="Select Landed Cost Code" AcceptButtonID="CstButton4" CancelButtonID="CstButton5">
<px:PXPanel runat="server" ID="CstPanel9">
<px:PXFormView runat="server" ID="CstFormView10" SkinID="Transparent" Width="100%" SyncPosition="True" DataMember="LandedCostCodeSelection" DataSourceID="ds">
<Template>
<px:PXSelector runat="server" ID="CstPXSelector11" DataField="LandedCostCodeID" CommitChanges="True" DataSourceID="ds">
</px:PXSelector>
</Template>
</px:PXFormView>
</px:PXPanel>
<px:PXPanel runat="server" ID="LandedCostCodeSelectionButtons" SkinID="Buttons">
<px:PXButton runat="server" ID="CstButton4" DialogResult="OK" Text="OK" />
<px:PXButton runat="server" ID="CstButton5" DialogResult="Cancel" Text="Cancel" />
</px:PXPanel></px:PXSmartPanel>
The code for the view that I'm referencing in the dialog is:
public PXSelect<LandedCostCode> LandedCostCodeSelection;
The code that I'm using to call the dialog is:
if (LandedCostCodeSelection.AskExt() == WebDialogResult.OK)
{
//rest of code here
}
What am I missing to allow the user to select or type a different Landed Cost Code?
Edit 1:
I have changed the code for the view that I'm referencing in the dialog to:
public PXFilter<LandedCostCode> LandedCostCodeSelection;
My aspx now looks like this:
<px:PXSmartPanel runat="server" ID="PanelAskForLCCode" Key="LandedCostCodeSelection" CaptionVisible="True" Caption="Select Landed Cost Code" AcceptButtonID="CstButton4" CancelButtonID="CstButton5" Width="300px" AutoRepaint="True" LoadOnDemand="True">
<px:PXFormView runat="server" ID="CstFormView18" CaptionVisible="False" Caption="LC Code Selection" DataSourceID="ds" DataMember="LandedCostCodeSelection">
<Template>
<px:PXLayoutRule runat="server" ID="CstPXLayoutRule19" StartColumn="True" ControlSize="XM" LabelsWidth="S"/>
<px:PXSelector runat="server" ID="CstPXSelector20" DataField="LandedCostCodeID" CommitChanges="True" DataSourceID="ds" DataMember="LandedCostCodeSelection"/>
</Template>
<CallbackCommands>
<Search CommitChanges="True"/>
</CallbackCommands>
</px:PXFormView>
<px:PXPanel runat="server" ID="LandedCostCodeSelectionButtons" SkinID="Buttons">
<px:PXButton runat="server" ID="CstButton4" DialogResult="OK" Text="OK"/>
<px:PXButton runat="server" ID="CstButton5" DialogResult="Cancel" Text="Cancel"/>
</px:PXPanel>
</px:PXSmartPanel>
I'm calling the dialog as follows:
if (LandedCostCodeSelection.AskExt((graph, view) =>
{
LandedCostCodeSelection.Cache.Clear();
},true) == WebDialogResult.OK)
{
}
I notice that when I click on the selector button and pick a row from the selector (which briefly returns a value to the field which is then overwritten right away) when I click on the selector button again, the selector has remembered the record I last selected.
Finally, if I invoke the dialog as follows:
if (LandedCostCodeSelection.AskExt((graph, view) =>
{
LandedCostCodeSelection.Cache.Clear();
LandedCostCodeSelection.Current.LandedCostCodeID = "XYZ";
},true) == WebDialogResult.OK)
{
}
Then the field is populated with XYZ and if I click OK I can reference the value of XYZ. (But if I use the selector, then the value is cleared and cannot be accessed again.)
The problem relies in the definition of the DataView and the DAC used. I have reproduced the issue and this is what I've changed to make it work:
Use a new custom DAC as a source for your view. Note that the field is not bound and is not key (does not have IsKey = true, as in LandedCostCode.LandedCostCodeID:
[Serializable]
[PXHidden]
public partial class LandedCostCodeFilter: IBqlTable
{
#region LandedCostCodeID
public abstract class landedCostCodeID : PX.Data.BQL.BqlString.Field<landedCostCodeID> { }
[PXString(15, IsUnicode = true)]
//[PXUnboudDefault("APPLE")] //optional, to preselect a value
[PXUIField(DisplayName = "Landed Cost Code",Visibility=PXUIVisibility.SelectorVisible)]
[PXSelector(typeof(Search<LandedCostCode.landedCostCodeID>))]
public virtual String LandedCostCodeID {get; set}
#endregion
}
Change the DataView definition, using a PXFilter instead of PXSelect and use the new DAC
public PXFilter<LandedCostCodeFilter> LandedCostCodeSelection;
Correct that and your dialog should work.
Obs.
If you want to have a value pre-selected when you open the dialog, add [PXUnboudDefault("APPLE")] to the field in the DAC
Not sure how does your button definition look like, but here is what it should be:
public PXAction<POLandedCostDoc> SelectLandedCost;
[PXButton]
[PXUIField(DisplayName = "Select Landed Cost Code", MapEnableRights = PXCacheRights.Delete, MapViewRights = PXCacheRights.Delete)]
protected void selectLandedCost()
{
if(LandedCostCodeSelection.AskExt(true) != WebDialogResult.OK) return;
// do some stuff here
}
Also, my aspx code:
<px:PXSmartPanel runat="server" ID="PanelAskForLCCode" Caption="Select Landed Cost Code" CaptionVisible="True" Key="LandedCostCodeSelection">
<px:PXFormView runat="server" ID="CstFormView2" DataMember="LandedCostCodeSelection" SkinID="Transparent" DataSourceID="ds" Height="100%" Width="100%">
<Template>
<px:PXLayoutRule runat="server" ID="CstPXLayoutRule3" StartColumn="True" />
<px:PXSelector runat="server" ID="CstPXSelector4" DataField="LandedCostCodeID" CommitChanges="True" AutoRefresh="True" />
<px:PXPanel runat="server" ID="LandedCostCodeSelectionButtons" SkinID="Buttons">
<px:PXButton runat="server" ID="CstButton6" DialogResult="OK" Text="OK" />
<px:PXButton runat="server" ID="CstButton7" DialogResult="Cancel" Text="Cancel" /></px:PXPanel></Template></px:PXFormView></px:PXSmartPanel>

How to create Master-Detail Grids in Acumatica?

I'm working on a custom page to visualize the relations between parent and child records by displaying the table data in a hierarchical order.
There are 2 data views in my BLC, which I'd like to use as the data source for two PXGrids to display the data in a master/detail format. When a record is selected in the master grid, all of the related child entries should be shown in the details grid.
How should I declare my 2 PXGrids in Aspx to accomplish this task?
For example, if some BLC contains a Categories data view and a Related Products data view, you would specify the Categories view to be the data source for the master grid and the Products view to be the data source for the details grid. When a category is selected in the master grid, all products associated with that category will be displayed in the details grid from the Products data view.
public class ProductCategories : PXGraph<ProductCategories>
{
#region Actions
public PXSave<Category> Save;
public PXCancel<Category> Cancel;
#endregion
#region Data Members
public PXSelect<Category> Categories;
public PXSelect<CategoryProduct,
Where<CategoryProduct.categoryID,
Equal<Current<Category.categoryID>>>> CategoryProducts;
#endregion
#region Event Handlers
protected virtual void Category_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
this.CategoryProducts.Cache.AllowInsert = e.Row != null;
}
#endregion
}
As shown in the code snippet above, the detail view is referenced with the master view via a Current BQL operator. Also, notice RowSelected event handler defined for the Category DAC to disable Insert button on the details grid if there is not a single record in the master grid.
The next step is to configure master-detail PXGrids in Aspx:
for the master grid set SyncPosition property to true, then define the AutoCallBack and OnChangeCommand properties as follows to accordingly refresh the detail grid every time a different record or no record at all will be selected in the master grid:
<px:PXGrid ID="masterGrid" runat="server" DataSourceID="ds" SkinID="Details"
SyncPosition="True" Caption="Categories" CaptionVisible="True" Width="100%">
<AutoCallBack Command="Refresh" Target="detailGrid" />
<OnChangeCommand Command="Refresh" Target="detailGrid" />
...
</px:PXGrid>
for the detail grid it's only required to define a Refresh CallbackCommand to force the master grid to select data along with the details grid. By doing the framework will raise the previously defined Category_RowSelected event handler and disable Insert button on the details grid in cases when there is no record in the master grid:
<px:PXGrid ID="detailGrid" runat="server" DataSourceID="ds" SkinID="Details"
Caption="Products" CaptionVisible="True" Width="100%">
<CallbackCommands>
<Refresh SelectControlsIDs="masterGrid" />
</CallbackCommands>
...
</px:PXGrid>
For the sake of better user experience, it's recommended to place master-detail PXGrids within a PXSplitContainer as shown in the code snippet below:
<px:PXSplitContainer runat="server" ID="sp" PositionInPercent="true" SplitterPosition="50"
SkinID="Horizontal" Orientation="Horizontal" Panel1MinSize="250" Panel2MinSize="250">
<AutoSize Enabled="true" Container="Window" />
<Template1>
<px:PXGrid ID="masterGrid" runat="server" DataSourceID="ds" SkinID="Details"
SyncPosition="True" Caption="Categories" CaptionVisible="True" Width="100%">
<AutoCallBack Command="Refresh" Target="detailGrid" />
<OnChangeCommand Command="Refresh" Target="detailGrid" />
<Levels>
<px:PXGridLevel DataMember="Categories">
<Columns>
...
</Columns>
</px:PXGridLevel>
</Levels>
<AutoSize Enabled="True" />
</px:PXGrid>
</Template1>
<Template2>
<px:PXGrid ID="detailGrid" runat="server" DataSourceID="ds" SkinID="Details"
Caption="Products" CaptionVisible="True" Width="100%">
<CallbackCommands>
<Refresh SelectControlsIDs="masterGrid" />
</CallbackCommands>
<Levels>
<px:PXGridLevel DataMember="CategoryProducts">
<Columns>
...
</Columns>
</px:PXGridLevel>
</Levels>
<AutoSize Enabled="True" />
</px:PXGrid>
</Template2>
</px:PXSplitContainer>
And here is how master-details PXGrids should look and operate inside an Acumatica webpage:

PXGrid with Preview - Preview does not show up

I am trying to show the preview text in one of my custom grid. This is similar to Activities tab on Case screen (CR306000). I have written below code but still it is not showing the preview text if I select Activities from the grid. Please suggest.
Code for DataView-
[PXFilterable]
[PXPreview(typeof(CRAcumaticaActivity))]
[PXViewName("AcumaticaActivities")]
public PXSelect<CRAcumaticaActivity,
Where<CRAcumaticaActivity.cloud9CaseID, Equal<Current<CRCase.caseCD>>>,
OrderBy<Desc<CRAcumaticaActivity.lastModifiedByDateTime>>> AcumaticaActivities;
HTML Code for gridwithpreview-
<px:PXTabItem Text="Acumatica Activities" LoadOnDemand="True">
<Template>
<pxa:PXGridWithPreview runat="server" PrimaryViewControlID="form" PreviewPanelStyle="z-index: 100; background-color: Window" GridSkinID="Inquire" PreviewPanelSkinID="Preview" NoteField="" AllowSearch="True" BlankFilterHeader="All Acumatica Activities" MatrixMode="true" DataSourceID="ds" DataMember="AcumaticaActivities" ID="grdAActivities" BorderWidth="0px" Width="100%">
<AutoSize Enabled="True" MinWidth="100" MinHeight="100" />
<ActionBar ActionsText="true" DefaultAction="AcuViewActivity" PagerVisible="False">
<CustomItems>
<px:PXToolBarButton Text="Get Activities">
<AutoCallBack Target="ds" Command="GetActivities" /></px:PXToolBarButton>
<px:PXToolBarButton Text="Publish Activity">
<AutoCallBack Target="ds" Command="PublishActivity" /></px:PXToolBarButton></CustomItems></ActionBar>
<GridMode AllowAddNew="False" AllowUpdate="False" AllowDelete="False" AllowFormEdit="False" AllowUpload="False" />
<Levels>
<px:PXGridLevel DataMember="AcumaticaActivities">
<RowTemplate />
<Columns>
<px:PXGridColumn DataField="ActivityID" Visible="False" AllowShowHide="False" AutoCallBack="true" />
<px:PXGridColumn DataField="Type" Width="250px" AutoCallBack="" />
<px:PXGridColumn DataField="Summary" Width="20" LinkCommand="AcuViewActivity" Visible="" />
<px:PXGridColumn DataField="Status" Width="50px" />
<px:PXGridColumn DisplayFormat="g" DataField="StartDate" Width="90px" />
<px:PXGridColumn DataField="Owner" Width="90px" /></Columns></px:PXGridLevel></Levels>
<PreviewPanelTemplate>
<px:PXHtmlView runat="server" DataField="Description" ID="edAcuDescrip" Height="100px" SkinID="Label" Width="100%">
<AutoSize Enabled="true" Container="Parent" /></px:PXHtmlView></PreviewPanelTemplate>
<CallbackCommands>
<Refresh PostData="Page" CommitChanges="True" /></CallbackCommands></pxa:PXGridWithPreview></Template></px:PXTabItem></Items>
<AutoSize Container="Window" Enabled="True" MinHeight="100" MinWidth="300" ></AutoSize>
</px:PXTab>
Finally found the answer and it is working now.
You should add PXPreview attribute to your Data View. In which first parameter should be your base DAC and second should be the child one.
For Example-
[PXPreview(typeof(CRCase), typeof(CRAcumaticaActivity))]
I was trying to recreate your setup but there is too much involved to get it working completely. However, I did notice that the DataField attribute on the PXHtmlView control is pointing to Description. It may not make a difference, but try changing it to description with a lower-case D and see if that solves the problem. I believe the DataField property needs to point to the class in the DAC and not the property itself.
Hope that helps.

crm 2011 ribbon: disable system button

I have a problem with disabling ribbon button via javascript custom rule.
The action for that I want to add "enable rule" is called Mscrm.AddExistingRecordFromSubGridAssociated -> which is displayed when subgrid gets focus.
I use the ribbon workbench solution and I almost sure I did everything fine, but it doesn't work.
javascript:
utils.ribbon.isAddExistingDisabled = function(grid) {
return false; //just for test I wrote always false, but it's enabled anyway :/
}
CommandDef:
<CommandDefinition Id="Mscrm.AddExistingRecordFromSubGridAssociated">
<EnableRules>
<EnableRule Id="Mscrm.AppendToPrimary" />
<EnableRule Id="Mscrm.EntityFormIsEnabled" />
<EnableRule Id="my.incident.addMainCause.EnableRule" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.AddExisting" />
<DisplayRule Id="Mscrm.ShowForManyToManyGrids" />
<DisplayRule Id="Mscrm.AppendToPrimary" />
<DisplayRule Id="Mscrm.AppendSelected" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addExistingFromSubGridAssociated" Library="/_static/_common/scripts/RibbonActions.js">
<CrmParameter Value="SelectedEntityTypeCode" />
<CrmParameter Value="SelectedControl" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
Enable rule def:
<EnableRule Id="my.incident.addMainCause.EnableRule">
<CustomRule FunctionName="utils.ribbon.isAddExistingDisabled" Library="$webresource:my_js/incident/common.js" InvertResult="false">
<CrmParameter Value="SelectedControl" />
</CustomRule>
</EnableRule>

How to bind dropdownlist in radgrid

I am new to use telerik controls. I want to bind data in dropdownlist that is in telerik RadGrid control. I have already been applied but it gives an error
Object reference not set to an instance of an object.
Here is my code given below :
Source code
<telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="false" AllowPaging="true"
OnNeedDataSource="RadGrid1_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand"
OnItemCreated="RadGrid1_ItemCreated" OnDeleteCommand="RadGrid1_DeleteCommand"
OnInsertCommand="RadGrid1_InsertCommand"
onitemdatabound="RadGrid1_ItemDataBound" >
<MasterTableView DataKeyNames="id" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" />
<telerik:GridBoundColumn DataField="id" HeaderText="ID" ReadOnly="true"
ForceExtractValue="Always" ConvertEmptyStringToNull="true" />
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:DropDownList ID="ddldept" DataTextField="name" DataValueField="id" runat="server"></asp:DropDownList>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="code" HeaderText="Branch Code" />
<telerik:GridBoundColumn DataField="name" HeaderText="Branch Name" />
<telerik:GridBoundColumn DataField="shortname" HeaderText="Branch Shorth Name" />
<telerik:GridBoundColumn DataField="hod" HeaderText="Head of Department"/>
<telerik:GridBoundColumn DataField="location" HeaderText="Location Address" />
<telerik:GridButtonColumn ConfirmText="Are you sure want to delete this Branch?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
</MasterTableView>
<PagerStyle Mode="NextPrevAndNumeric" />
<ClientSettings>
<ClientEvents OnRowDblClick="rowDblClick" />
</ClientSettings>
</telerik:RadGrid>
Main Code
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
DataTable dt=obj.display_branch();
GridEditableItem item = e.Item as GridEditableItem;
DropDownList list = item.FindControl("ddldept") as DropDownList;
list.DataSource = dt;
list.DataTextField = "name";
list.DataValueField = "id";
list.DataBind();
}
Try on RadGrid1_ItemCreated. That is how I achieved it.

Resources