I have an application that using MVC pattern, ZK 8 version and Tree component as a menu. The application itself using border layout and Tabbox as a dynamic container. The menu tree code is adding tab when it is clicked. I have successfuly do this, but in an inefficient manner. Is there an efficient alternatives or ways to refactor?
The codes are:
<zk>
<style src="css/style.css" />
<borderlayout>
<north>
<div height="120px"
style="background:#3461b2
url('images/banner.jpg')no-repeat;" />
</north>
<west title="Selamat Datang - ${sessionScope.userCredential.name}"
size="22%" autoscroll="true" splittable="true" collapsible="true"
vflex="max">
<tree id="menuTree">
<treechildren>
<treeitem label="Daily">
<treechildren>
<treeitem label="Report 1">
<attribute name="onClick">
<![CDATA[
Tab newTab;
if (mainTabbox.getTabs().hasFellow("Report 1")) {
newTab = (Tab) mainTabbox.getTabs().getFellow("Report 1");
mainTabbox.setSelectedTab(newTab);
} else {
newTab = new Tab("Report 1");
newTab.setId("Report 1");
newTab.setClosable(true);
newTab.setSelected(true);
Tabpanel tb = new Tabpanel();
Executions.createComponents("daily/report1.zul", tb, null);
mainTabbox.getTabs().appendChild(newTab);
mainTabbox.getTabpanels().appendChild(tb);
}
]]>
</attribute>
</treeitem>
<treeitem label="Logs">
<attribute name="onClick">
<![CDATA[
Tab newTab;
if (mainTabbox.getTabs().hasFellow("Logs")) {
newTab = (Tab) mainTabbox.getTabs().getFellow("Logs");
mainTabbox.setSelectedTab(newTab);
} else {
newTab = new Tab("Logs");
newTab.setId("Logs");
newTab.setClosable(true);
newTab.setSelected(true);
Tabpanel tb = new Tabpanel();
Executions.createComponents("Logs.zul", tb, null);
mainTabbox.getTabs().appendChild(newTab);
mainTabbox.getTabpanels().appendChild(tb);
}
]]>
</attribute>
</treeitem>
...
...
<center vflex="min" autoscroll="true">
<div height="100%">
<tabbox id="mainTabbox">
<tabs id="tabs">
<tab id="mainTab" label="Main" />
</tabs>
<tabpanels>
<tabpanel>
<include src="/charts/mainChart.zul" />
</tabpanel>
</tabpanels>
</tabbox>
</div>
</center>
....
I found the solution by using onSelect listener attribute:
<tree id="menuTree">
<attribute name="onSelect">
<![CDATA[
Treeitem item = self.getSelectedItem();
if (item != null) {
Tab newTab;
if (mainTabbox.getTabs().hasFellow(item.getLabel())) {
newTab = (Tab) mainTabbox.getTabs().getFellow(item.getLabel());
mainTabbox.setSelectedTab(newTab);
} else {
newTab = new Tab(item.getLabel());
newTab.setId(item.getLabel());
newTab.setClosable(true);
newTab.setSelected(true);
Tabpanel tb = new Tabpanel();
Executions.createComponents(item.getValue().toString(), tb, null);
mainTabbox.getTabs().appendChild(newTab);
mainTabbox.getTabpanels().appendChild(tb);
}
}
]]>
</attribute>
<treechildren>
<treeitem label="Daily">
<treechildren>
<treeitem label="Tab Label" value="somepage.zul" />
<treeitem label="Other Tab Label" value="otherpage.zul" />
....
reference from: http://forum.zkoss.org/question/3675/tree-onselect-eventlistener/
Related
I have a Razor Component (.net 6) where I make use of the Radzen DataGrid Multiple Selection.
<RadzenDataGrid
#ref="contactsGrid" Data="#contacts" AllowColumnResize="true" EditMode="DataGridEditMode.Single"
RowUpdate="#OnUpdateRow" RowCreate="#OnCreateRow"
AllowSorting="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
TItem="ContactModel" AllowRowSelectOnRowClick="false" SelectionMode="DataGridSelectionMode.Multiple" #bind-Value=#selectedContacts>
<Columns>
<RadzenDataGridColumn TItem="ContactModel" Width="40px" Sortable="false" Filterable="false">
<HeaderTemplate>
<RadzenCheckBox TriState="false" TValue="bool" Value="#(contacts.Any(i => selectedContacts != null && selectedContacts.Contains(i)))" Change="#(args => selectedContacts = args ? contacts.ToList() : null)" />
</HeaderTemplate>
<Template Context="contacts">
<RadzenCheckBox TriState="false" Value="#(selectedContacts != null && selectedContacts.Contains(contacts))" TValue="bool" Change=#(args => { contactsGrid.SelectRow(contacts); }) />
</Template>
</RadzenDataGridColumn>
<!-- FirstName -->
<RadzenDataGridColumn TItem="ContactModel" Property="FirstName" Title="FirstName">
<EditTemplate Context="contact">
<RadzenTextBox #bind-Value="contact.FirstName" Style="width:100%; display: block" Name="FirstName" />
<RadzenRequiredValidator Text="FirstName is required" Component="FirstName" Popup="true" />
</EditTemplate>
</RadzenDataGridColumn>
<!-- LastName -->
<RadzenDataGridColumn TItem="ContactModel" Property="LastName" Title="LastName">
<EditTemplate Context="contact">
<RadzenTextBox #bind-Value="contact.LastName" Style="width:100%; display: block" Name="LastName" />
<RadzenRequiredValidator Text="LastName is required" Component="LastName" Popup="true" />
</EditTemplate>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
In the HeaderTemplate you can directly select or deselect all items.
Is it possible to change the function so that only all items are selected that match the filter? i.e. which items are currently displayed when I search for certain items using the filter option?
you can use contactsGrid.View to get visible rows. try to use contactsGrid.View instead of selectedContacts.
Good day,
I have a GridTemplateColumn with a RadTextbox. The textbox values are changed by javascript. But when i click the textbox,it changes back to its original value.
Please help
javascript
<title>Untitled Page</title>
<script type="text/javascript">
function changeCountry() {
var grid = $find('<%=RadGrid1.ClientID %>');
var MasterTable = grid.get_masterTableView();
var dataItems = MasterTable.get_dataItems();
var cellCountry = dataItems[0].get_cell("CountryCol");
var txtCountry = $telerik.$(cellCountry).find('input')[0];
txtCountry.value = "New Country";
}
</script>
.aspx
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" CellSpacing="0" GridLines="None" PageSize="20" AutoGenerateColumns="false" OnItemDataBound="RadGrid1_ItemDataBound">
<FilterMenu EnableImageSprites="False">
</FilterMenu>
<ClientSettings>
<Selecting CellSelectionMode="None" AllowRowSelect="True" />
</ClientSettings>
<MasterTableView>
<CommandItemSettings ExportToPdfText="Export to PDF" />
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="CR_Branch" HeaderText="Branch"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CR_Country" HeaderText="Branch" Display=false></telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="CR_Country" DataField="CR_Country" UniqueName="CountryCol">
<ItemTemplate>
<telerik:RadTextBox ID="txtCountry" runat="server"></telerik:RadTextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
.aspx.cs
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridHeaderItem)
{
}
if (e.Item is GridDataItem)
{
GridDataItem dataItem = (GridDataItem)e.Item;
RadTextBox txtCountry = ((RadTextBox)dataItem.FindControl("txtCountry"));
txtCountry.Text = dataItem["CR_Country"].Text;
}
}
You need to use the Telerik client script set_value function rather than pure javascript/HTML, i.e.
function changeCountry() {
var grid = $find('<%=RadGrid1.ClientID %>');
var MasterTable = grid.get_masterTableView();
var dataItems = MasterTable.get_dataItems();
dataItems[0].findControl("txtCountry").set_value("New Country");
}
I am trying to create ajax tabs dynamically and storing their ID's in a session. I am getting an error "Specified argument was out of the range of valid values.
Parameter name: value". I am able to create the first tab by invoking the click button event. When I click the button and invoke the same event on the second try...I get the error. Seems like I am referencing a tab ID or container\tab that is no longer defined or contained in session?
I have researched this thoroughly and can't seem to find the answer. Any help would be greatly appreciated.
I have the correct scriptmanager and assembly references on my asp page. Here is the asp code and the code behind snippet.
<div>
<asp:Button ID ="AddTab" Text="Add Tab" OnClick = "addTab_Click" runat="server"/>
<AjaxToolkit:TabContainer ID="TabContainerContent" runat="server" Height="150px" BackColor="White" AutoPostBack="True"
OnActiveTabChanged="TabContainerContent_OnActiveTabChanged" >
</AjaxToolkit:TabContainer>
<asp:Label ID="currentTabIndex" runat="server"></asp:Label>
</div>
</td>
Code Behind
private List<string> dynamicTabIDs;
protected void Page_Init(Object sender, EventArgs e)
{
if (Session["dynamicTabIDs"] != null)
{
dynamicTabIDs = (List<string>)Session["dynamicTabIDs"];
foreach (string tabID in dynamicTabIDs)
{
AjaxControlToolkit.TabPanel tab = new AjaxControlToolkit.TabPanel();
tab.ID = tabID;
tab.HeaderText = "Tab " + (TabContainerContent.Tabs.Count + 1).ToString();
Label tabContent = new Label();
tabContent.ID = "lbl_tab_" + TabContainerContent.Tabs.Count.ToString();
tabContent.Text = "Tab " + (TabContainerContent.Tabs.Count + 1).ToString();
tab.Controls.Add(tabContent);
TabContainerContent.Tabs.Add(tab);
}
}//end if
else
{
dynamicTabIDs = new List<string>();
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
Session["dynamicTabIDs"] = dynamicTabIDs;
}
protected void TabContainerContent_OnActiveTabChanged(object sender, EventArgs e)
{
currentTabIndex.Text = TabContainerContent.ActiveTab.ID;
}
public void addTab_Click(object sender, EventArgs e)
{
AjaxControlToolkit.TabPanel tab = new AjaxControlToolkit.TabPanel();
tab.ID = "tab" + Convert.ToString(TabContainerContent.Tabs.Count);
tab.HeaderText = "Tab " + (TabContainerContent.Tabs.Count + 1).ToString();
Label tabContent = new Label();
tabContent.ID = "lbl_tab_" + TabContainerContent.Tabs.Count.ToString();
tabContent.Text = "Tab " + (TabContainerContent.Tabs.Count + 1).ToString();
tab.Controls.Add(tabContent);
TabContainerContent.Tabs.Add(tab);
TabContainerContent.ActiveTab = tab;
dynamicTabIDs.Add(tab.ID);
}
I tried a different approach to accomplsih this. I created static tabs and just set them to visible true/false depending if they are used or not. I couldn't get dynamic tabs to work. I did have to restrict the number of customer numbers to 15 orders with this approach.
I found that it was very easy to bind data to a gridview within Ajax tabs. Of course you needed you script manager ajax reference declared in the asp page and ajax reference update to web.config file. You also need to add the ajax css style to an existing style sheet. i tried using a seperate one and it didn't work.
ASP HTML
<AjaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0"
Visible="false" ScrollBars="Both"
CssClass="Tab2" Width="1326px" Height="464px" >
<AjaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="Empty" Enabled="true" ScrollBars="Both" CssClass="Tab2">
<ContentTemplate>
<div style="overflow:auto;width:1287px; height: 418px;">
<font color="white" size="1" face="Verdana">
<asp:GridView ID="SalesOrderView1" runat="server" BackColor="White" BorderColor="#DEDFDE"visible="False"BorderStyle="None" BorderWidth="1px"
CellPadding="4" ForeColor="Black"
GridLines="Vertical" HorizontalAlign="Center">
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>
</div>
</font>
</ContentTemplate>
</AjaxToolkit:TabPanel>
<AjaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="Empty" ScrollBars="Both" CssClass="Tab2">
<ContentTemplate >
</AjaxToolkit:TabContainer>
C# Code to bind data to the gridview on click button event.
SalesOrderView1.Visible = true;
TabPanel1.Visible = true;
TabPanel1.HeaderText = Order_List[multi_order_count];
I have a radTreeView like this.
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
<telerik:RadTreeView ID="RadTreeView1" CheckBoxes="true" Runat="server"
OnContextMenuItemClick= "menuClicked" OnClientContextMenuItemClicking="clientMenuClicking"
OnNodeEdit="RadTreeView1_NodeEdit">
<ContextMenus>
<telerik:RadTreeViewContextMenu ID="ctxMenuAdd" runat="server">
<Items>
<telerik:RadMenuItem Value="addNode" Text="Add Node">
</telerik:RadMenuItem>
<telerik:RadMenuItem Value="delNode" Text="Delete Node">
</telerik:RadMenuItem>
<telerik:RadMenuItem Value="renNode" Text="Rename Node">
</telerik:RadMenuItem>
</Items>
</telerik:RadTreeViewContextMenu>
</ContextMenus>
</telerik:RadTreeView>
</telerik:RadAjaxPanel>
This is the ContextMenuClicking javascript in client side.
function clientMenuClicking(sender, args)
{
var menuItem = args.get_menuItem();
var treeNode = args.get_node();
menuItem.get_menu().hide();
switch (menuItem.get_value())
{
case "addNode":
var windowResult = window.showModalDialog("newNode.html", "Enter Value", "dialogHeight: 300px; dialogWidth: 300px;");
document.getElementById("HiddenField1").value = windowResult;
break;
case "renNode":
treeNode.startEdit();
break;
}
}
finally this is the server side code for onNodeEdit
protected void RadTreeView1_NodeEdit(object sender, RadTreeNodeEditEventArgs e)
{
e.Node.Text = e.Text;
}
The problem is, when I right click on the node and select "Rename" the node turns into a text box only for a split second, then it goes back to normal mode.
How can I get rid of the issue?
I am working on extending an ASP.NET 2.0 application using an InterBase database. My experience is in PHP/MySQL, so my familiarity with ASP is currently in the 2-week range, and is pieced together from examining a co-worker's code, the first 90 pages of my ASP book, and Google. In the application, I have an SqlDataSource control connecting to my database and selecting the information I need. Then the results are copied into a DataView where I modify the data in one of the columns, and then I push that DataView to a GridView for output. The issue I'm having is that I cannot sort the GridView at this point. I followed instructions here: http://forums.asp.net/p/956540/1177923.aspx, but to no avail.
Here is the page code:
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="Products" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:ConnectionString1.ProviderName %>" OnLoad="ProductsDS_Load"
OnSelected="ProductsDS_Selected" DataSourceMode="DataSet">
</asp:SqlDataSource>
<br />
<asp:Label ID="testlabel" runat="server"></asp:Label>
<br />
<asp:Label ID="testlabel2" runat="server"></asp:Label>
<br /><br />
This table lists all 2000+ numbered projects which are at least partially in process.<br />
The Project number link leads to a more detailed view of that project.<br />
<br />
<asp:Label runat="server" ID="numrows"></asp:Label> results returned.
<br />
<asp:GridView ID="ProductsView" runat="server" EnableModelValidation="True"
AutoGenerateColumns="False" CellPadding="4" OnSorting="ProductsView_Sorting"
ForeColor="#333333" GridLines="None" AllowSorting="True">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:HyperLinkField HeaderText="Project" SortExpression="PROJECT"
DataTextField="PROJECT" Target="subweeklyreport" DataNavigateUrlFields="PROJECT"
DataNavigateUrlFormatString="Products.aspx?p={0}" />
<asp:BoundField Visible="false" DataField="PROJECTID" />
<asp:BoundField DataField="PART" HeaderText="Part #"
SortExpression="PART" />
<asp:BoundField DataField="DESCRIPTION" HeaderText="Description"
SortExpression="DESCRIPTION" />
<asp:BoundField DataField="ENGMGR" HeaderText="Eng. Mgr."
SortExpression="ENGMGR" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
</div>
</form>
And here is the code behind:
protected void ProductsDS_Load(object sender, EventArgs e)
{
string SQLQuery = Query would go here;
testlabel2.Text = SQLQuery;
Products.SelectCommand = SQLQuery;
Products.DataBind();
DataView dv = (DataView)Products.Select(new DataSourceSelectArguments());
foreach (DataRow dr in dv.Table.Rows)
{
string name = dr["ENGMGR"].ToString();
string[] explode = name.Split(' ');
string newname;
if (explode.Length == 3)
{
newname = explode[2] + ", " + explode[0];
}
else
{
newname = explode[1] + ", " + explode[0];
}
dr["ENGMGR"] = newname;
//testlabel.Text = dr["ENGMGR"].ToString();
}
Products.DataBind();
//ProductsView.DataSourceID = "Products";
ProductsView.DataSource = dv;
ProductsView.DataBind();
ProductsView.Enabled = true;
ProductsView.Visible = true;
}
protected void ProductsDS_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
numrows.Text = e.AffectedRows.ToString();
}
protected void ProductsView_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = ProductsView.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
ProductsView.DataSource = dataView;
ProductsView.DataBind();
}
}
private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
return newSortDirection;
}
What I think is happening is that whenever the GridView does the postback for the sort, it causes the query to be executed again and overwrite the attempt to sort the existing data in the GridView, but I don't know enough about ASP right now to prevent this behavior. Any help would be much appreciated.
I ended up solving my own problem. I created a session variable to store the dataview between page loads, and checking to see if the dataview is stored before executing the query, and sorting it if it is, and just performing the regular query otherwise. Since I don't expect data to be introduced between the initial page view and the sort, I don't think using a stored copy of the data would be a major issue.