SAPUI5 OData binding to table - data-binding

I try to bind campaign data from the OData service CUAN_CAMPAIGN_SRV to a TableSelectDialog element. In my view I have an Input field with input help:
<form:FormElement visible="true">
<form:label>
<Label text="Campaign" design="Standard" width="100%" required="false" textAlign="Begin" textDirection="Inherit"/>
</form:label>
<form:fields>
<Input id="campaignId" type="Text" enabled="true" visible="true" width="auto" editable="true" showValueHelp="true" valueHelpOnly="true" valueHelpRequest="handleValueHelp"/>
</form:fields>
The value help calls the function handleValueHelp in my controller:
handleValueHelp: function(oController) {
this.inputId = oController.oSource.sId;
// create value help dialog
if (!this._valueHelpDialog) {
this._valueHelpDialog = sap.ui.xmlfragment(
"my.view.Campaigns",
this
);
this.getView().addDependent(this._valueHelpDialog);
}
// open value help dialog
this._valueHelpDialog.open();
}
This is when my table dialog (fragment) pops up:
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
<TableSelectDialog id="campaignSelect" title="Select campaign" items="{path:'/CampaignSet'}" growingThreshold="5">
<columns>
<Column>
<Text text="Name"/>
</Column>
<Column>
<Text text="ID"/>
</Column>
<Column>
<Text text="Created at"/>
</Column>
<Column>
<Text text="Created by"/>
</Column>
</columns>
<items>
<ColumnListItem>
<Text text="{CampaignName}"/>
<Text text="{CampaignId}"/>
<Text text="{CreatedOn}"/>
<Text text="{CreatedBy}"/>
</ColumnListItem>
</items>
</TableSelectDialog>
So I tried to bind the EntitySet CampaignSet from OData Service CUAN_CAMPAIGN_SRV to the table. Therefore I added this code to my init() function of the controller:
var uname = "UNAME";
var pw = "PW";
var oModel = new sap.ui.model.odata.v2.ODataModel("https://host:port/sap/opu/odata/sap/CUAN_CAMPAIGN_SRV/",
true, uname, pw);
this.getView().setModel(oModel);
The problem is: the table contains no data and this error shows up in the console:
Translated from german: "In the context of Data Services an unknown internal server error occured"
iwfnd/error_log says this:
Invalid format (return table): Row Number 1, Property Name
'ChangedOn', Property Value '0 '
Why does ChangedOn even matter if I don't want to bind this property?
I can call something like below directly in browser with success:
https://host:port/sap/opu/odata/sap/CUAN_CAMPAIGN_SRV/CampaignSet('100001625')/CampaignName
What do I do wrong? Thank you for every hint!
ChangedOn is set to Nullable in the service definition:

Related

Flex Datagrid Column Total

I have a data grid that that has a title, price, qty and total column. The title, price and qty data is loaded from an xml file and the total is populated with a labelFunction to multiply the price by the qty.
I'm able to populate the total for each row with a labelFunction by returning a string to the row under the total column, but I'm having trouble figuring out how to get the overall total for the total column. I'd like to get the overall total and display it in a textBox/somewhere else outside of the datagrid.
I'm able to get the total by using the updateEsimate function, but it'll only send the total using itemEditEnd on the datagrid (which means i'd have to click on eat qty row for it to tally up) and I'd like it to give me the total automatically once it loads.
Help Please!
(some sample code)
public function updateEstimate(event:DataGridEvent):void
{
// TODO Auto-generated method stub
var sum:Number = 0;
for(var i:int=0; i<orderGrid.dataProvider.length ; i++) {
sum += Number(orderGrid.dataProvider.getItemAt(i).total);
totaltxt.text = sum.toString();
}
totaltxt.text = sum.toString();
}
public function getTotal(item:Object, column:DataGridColumn):String
{
var sum:Number = item.price * item.quantity;
return sum.toString();
}
<mx:XMLListCollection id="xmlProdListColl"
source="{productXML.lastResult.offer}"
/>
</fx:Declarations>
<mx:DataGrid id="orderGrid" x="44" y="0" width="640" height="155"
dataProvider="{xmlProdListColl}"
doubleClickEnabled="true" editable="true"
itemEditEnd="orderGrid_itemEditEndHandler(event); updateEstimate(event)">
<mx:columns>
<mx:DataGridColumn headerText="Title" dataField="title" editable="false"/>
<mx:DataGridColumn headerText="Price" dataField="price" editable="false"/>
<mx:DataGridColumn headerText="Quantity" dataField="quantity"/>
<mx:DataGridColumn headerText="Total" labelFunction="getTotal" editable="false"/>
</mx:columns>
</mx:DataGrid>
<s:RichText id="totaltxt" width="147" height="84" fontSize="18" text="" textAlign="center"
verticalAlign="middle" />
From what i see you calculate the totals in getTotal() to display the totals but are not settings the "total" property in the actual object. And it is the total property that you use in updateEstimate(). So whenever you would edit the quantities you still would see correct total in the datagrid but the value in the textfield would remain the same
I am not a big fan of binded dataProviders because you never know when data is available and it's hard to modify it (like we need it here). I prefer my own dataProvider variables that are strong typed and that I can modify as I wish :)
So I would do it this way:
I assume, your XML looks somethign like this and you don't have the "total" value in it:
<root>
<lastResult>
<offer>
<title>Title</title>
<price>20</price>
<quantity>1</quantity>
</offer>
<offer>
<title>Title 2</title>
<price>30</price>
<quantity>2</quantity>
</offer>
</lastResult>
At some point in your code you will have your XML. This is where you modify it adding a total property and pass the dataProvider to the grid:
private var _orderDataProvider:XMLListCollection;
private function gotData():void
{
var list:XMLList = new XMLList(productXML.lastResult.offer);
_orderDataProvider = new XMLListCollection(list);
updateEstimate(); // call this before we assign the dataprovider to the grid, so we will have totals in items
orderGrid.dataProvider = _orderDataProvider;
}
public function updateEstimate(event:DataGridEvent = null):void
{
// update all totals in all items and the "Estimated total" in one go
var sum:Number = 0;
for (var i:int = 0; i < _orderDataProvider.length; i++)
{
var item:Object = _orderDataProvider.getItemAt(i);
item.total = item.quantity * item.price;
sum += Number(_orderDataProvider.getItemAt(i).total);
}
totaltxt.text = sum.toString();
}
MXML:
<mx:DataGrid id="orderGrid"
x="44"
y="0"
width="640"
height="155"
doubleClickEnabled="true"
editable="true"
itemEditEnd="updateEstimate(event)">
<mx:columns>
<mx:DataGridColumn headerText="Title"
dataField="title"
editable="false"/>
<mx:DataGridColumn headerText="Price"
dataField="price"
editable="false"/>
<mx:DataGridColumn headerText="Quantity"
dataField="quantity"/>
<mx:DataGridColumn headerText="Total"
dataField="total"
editable="false"/>
</mx:columns>
</mx:DataGrid>
<s:RichText id="totaltxt"
width="147"
height="84"
fontSize="18"
text=""
textAlign="center"
verticalAlign="middle"/>
Now as you see this is not the ideal code because we update totals in ALL items every time on edit although you edit only one entry but we don't have to mess with several functions, so as long as you don't have 1000 entries in your list it should be fine.
You can use the CollectionEvent on the XMLListCollection instead. This will get dispatched at the beginning and when any updates are made to the data:
public function updateEstimate(event:CollectionEvent):void{
// your update code
}
<mx:XMLListCollection id="xmlProdListColl"
collectionChange="updateEstimate(event)"
source="{productXML.lastResult.offer}"/>

Devexpress silverlight grid header checkbox column

Is it possible to select or deselect the check box ( silverlight devexpress grid check box ) based on Grid header checkbox column , using client side events or server side events.
Sample Code :
<dxg:GridControl.View>
<dxg:TableView NavigationStyle="Cell" VerticalContentAlignment="Top" AllowColumnFiltering="True" AllowFilterEditor="True" ShowTotalSummary="True" Foreground="Black" ShowGroupPanel="False" AllowEditing="False" >
</dxg:TableView>
</dxg:GridControl.View>
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="EID" Fixed="Left" Width="70" VerticalAlignment="Top" AllowFocus="False" FilterPopupMode="CheckedList"></dxg:GridColumn>
<dxg:GridColumn FieldName="EN" Header="Name" Width="180" AutoFilterCondition="Contains" Fixed="Left" VerticalAlignment="Top" AllowFocus="False" FilterPopupMode="CheckedList" />
<dxg:GridColumn FieldName="DOJ" Header="Date Of Joining" Width="110" AllowFocus="False" FilterPopupMode="CheckedList" />
<dxg:GridColumn FieldName="CEX" Width="170" Visible="True" AutoFilterCondition="Like" AllowFocus="False" FilterPopupMode="CheckedList" />
<dxg:GridColumn FieldName="CheckBoxColumn" Width="170" Visible="True" AutoFilterCondition="Like" AllowFocus="False" FilterPopupMode="CheckedList" />
</dxg:GridControl.Columns>
<dxg:GridControl.GroupSummary>
<dxg:GridSummaryItem SummaryType="Count" />
</dxg:GridControl.GroupSummary>
<dxg:GridControl.TotalSummary>
<dxg:GridSummaryItem FieldName="EID" ShowInColumn="EN" SummaryType="Count"/>
</dxg:GridControl.TotalSummary>
</dxg:GridControl>
You have to modify the cell template in order to achieve what you want.
It will be something like this:
<dxg:GridColumn VisibleIndex="38" Header="h1" FieldName="h1" Name="h1">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:CheckEdit IsChecked="True" HorizontalAlignment="Center">
</dxe:CheckEdit>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
After creating the new template you can access your Column and load its content in order to modify the element within it:
var checkBox = MyGrid.Columns["h1"].CellTemplate.LoadContent() as DevExpress.Xpf.Editors.CheckEdit
Then
checkBox.IsChecked = true
Hope it helps!

how to sort struts2jquerygrid column by default onload in client

I have used Struts2JqueryGrid and I did client side sorting by enable loadonce =true, but it will work while click the column header only. I want shot a column by default on pageload or gridload.
My code is
<sjg:grid id="grid_vehicleedit"
dataType="json"
href="%{remoteurl}"
loadonce="true"
gridModel="vchlst"
draggable="false"
hoverrows="false"
sortable="true"
viewrecords="true"
sortable="true"
>
<sjg:gridColumn name="vname" index="vname" sortable="true" title="Vehicle Name" key="true" />
<sjg:gridColumn name="imei" sorttype="int" sortable="true" title="Imei" index="imei" />
<sjg:gridColumn name="dtype" sortable="true" title="Splitter Type" width="80" index="dtype"/>
</sjg:grid>
Try adding these two attributes to your <sjg:grid> tag:
sortname="vname"
sortorder="asc"
And delete one of the occurrences of sortable="true". So you should end up with:
<sjg:grid id="grid_vehicleedit"
dataType="json"
href="%{remoteurl}"
loadonce="true"
gridModel="vchlst"
draggable="false"
hoverrows="false"
viewrecords="true"
sortable="true"
sortname="vname" // determines which column you want sorted on gridload
sortorder="asc" // default is ascending; use desc for descending
>
<sjg:gridColumn name="vname" index="vname" sortable="true" title="Vehicle Name" key="true" />
<sjg:gridColumn name="imei" index="imei" sorttype="int" sortable="true" title="Imei" />
<sjg:gridColumn name="dtype" index="dtype" sortable="true" title="Splitter Type" width="80" />
</sjg:grid>

Disabled button when textbox is empty in silverlight mvvm?

i'm working on silverlight with MVVM pattern. in design page i have three textbox and one button. here my requirement is if the 3 textbox is empty or null means the button is disabled.
how to achieve this.. any help..?
Create a public property in your VM that checks the conditions you've stated above and returns a Boolean accordingly. Bind this property to your button IsEnabled property.
Make sure to fire PropertyChangedEvent once every condition status is changed (i.e in the textbox changed event).
Here i have attached my coding..
Xaml:
<Button Content="Add" Width="59" IsEnabled="{Binding ButtonIsEnabled}" Height="23" Margin="256,75,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" TabIndex="4" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<si:CallDataMethod Method="AddEmployee"/>
<si:SetProperty TargetName="LayoutRoot" PropertyName="Background" Value="LightBlue"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<TextBlock FontWeight="Bold" Height="26" HorizontalAlignment="Left" Margin="47,12,0,0" Name="textBlock1" Text="First Name:" VerticalAlignment="Top" Width="77" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="130,12,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" Text="{Binding Fname,Mode=TwoWay}" TabIndex="1" AcceptsReturn="False">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<si:CallDataMethod Method="ButtonIsEnabled"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
<TextBlock FontWeight="Bold" Height="25" HorizontalAlignment="Left" Margin="35,44,0,0" Name="textBlock2" Text="Second Name:" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="130,44,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" Text="{Binding Sname,Mode=TwoWay}" TabIndex="2" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<si:CallDataMethod Method="ButtonIsEnabled"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
<TextBlock FontWeight="Bold" Height="23" HorizontalAlignment="Left" Margin="45,75,0,0" Name="textBlock3" Text="Department:" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="130,75,0,0" Name="textBox3" VerticalAlignment="Top" Width="120" Text="{Binding Dept,Mode=TwoWay}" TabIndex="3" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<si:CallDataMethod Method="ButtonIsEnabled"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
ViewModel Code:
EmployeeListViewModel.cs
public bool ButtonIsEnabled
{
get
{
return !(((string.IsNullOrEmpty(this.Fname)) && (string.IsNullOrEmpty(this.Sname)) && (string.IsNullOrEmpty(this.Dept))));
}
}
private string _fname;
public string Fname
{
get
{
return _fname;
}
set
{
if (_fname != value)
{
_fname = value;
RaisePropertyChanged("Fname");
//RaisePropertyChanged("ButtonIsEnabled");
}
else
{
_fname = value;
RaisePropertyChanged("Fname");
}
}
}
private string _sname;
public string Sname
{
get
{
return _sname;
}
set
{
if (_sname != value)
{
_sname = value;
RaisePropertyChanged("Sname");
RaisePropertyChanged("ButtonIsEnabled");
}
else
{
_sname = value;
RaisePropertyChanged("Sname");
}
}
}
private string _dept;
public string Dept
{
get
{
return _dept;
}
set
{
if (_dept != value)
{
_dept = value;
RaisePropertyChanged("Dept");
RaisePropertyChanged("ButtonIsEnabled");
}
else
{
_dept = value;
RaisePropertyChanged("Dept");
}
}
}
My Problem is:
1) It is worked for the 1st textbox. while i entered anything in the 1st textbox the button is in disabled mode. But if i moved to the 2nd TextBox means the button is enabled.
2) I need all the textbox will Validated after that only Button is enabled. If any one of the Textbox is Empty means the button is again went to disabled mode..
Any Help..?
If you are using Silverlight 5 then there is a very nice solution of MultiBinding through custom markup extensions: MultiBinding in Silverlight 5.
There is also an IMultiValueConverter which allows you to convert collection of binded values to single value (in your case - bool). Using both extension and converter you can easily achieve desired functionality.

Select parent row where expand subgrid in JQGrid

I have a JQGRid with two hierarchical level. I want to perform row selection when I expand a subgrid from the parent, because if I click on the plus icons, the row of the master grid is not selected.
I am trying to fire this code whene the sub grid is expanded, but it doers not work:
function showSubGrid(subgrid_id, row_id)
{
jQuery("#<%= jqGrid.ClientID %>").setSelection(row_id, true);
showSubGrid_jqGrid(subgrid_id, row_id);
}
This javascript function is fired whene the subgrid is expanded from the parent. Here is my server side code:
<trirand:JQGrid ID="jqMasterGrid" runat="server" Height="400px" AutoWidth="False" OnSorting="jqMasterGrid_OnSorting">
<Columns>
<trirand:JQGridColumn DataField="COD_VALUTAZIONE" Width="220" HeaderText = "Codice Valutazione" PrimaryKey="True" Sortable="True" />
<trirand:JQGridColumn DataField="InfAsp" Width="170" TextAlign="Center" Sortable="True"/>
<trirand:JQGridColumn DataField="LineaAsp" Width="170" TextAlign="Center" Sortable="True"/>
<trirand:JQGridColumn DataField="SuperAsp" Width="170" TextAlign="Center" Sortable="True"/>
<trirand:JQGridColumn DataField="Eccellente" Width="170" TextAlign="Center" Sortable="True"/>
</Columns>
<ToolBarSettings
ShowAddButton="false" ShowDeleteButton="false" ShowEditButton="false" ShowRefreshButton="false"
ShowSearchButton="false" ShowViewRowDetailsButton="false" ToolBarPosition="Hidden" ShowSearchToolBar="False" ShowInlineDeleteButton="False" ShowInlineEditButton="True" />
<HierarchySettings HierarchyMode="Parent" />
<ClientSideEvents SubGridRowExpanded="showSubGrid"/>
<ClientSideEvents LoadComplete="jqLoadComplete"></ClientSideEvents>
<PagerSettings PageSize="2000" />
</trirand:JQGrid>
Can you please help?
Use this in your parent jqgrid:
HierarchySettings HierarchyMode="Parent" SelectOnExpand="true"
By using this code when you will expand a row in parent jqgrid then the row in parent jqgrid will be selected.
Okay try something like this
subGridRowExpanded: function (subgrid_id, row_id) {
$("#grid").jqGrid('setSelection', "row_id");
}
I can not test my code right now, but if this doesn't work then let me know.

Resources