Show/Hide columns in App Maker Table? - google-app-maker

Is it possible to allow the user to dynamically show or hide columns in the Table widget? Or would that require creating a custom table? If a custom table, what would the basic steps for that be?
Any assistance is much appreciated. Thank you.

In AppMaker, there are no columns, only rows. The way you organize the widgets inside the rows is what gives you the column like display. But to answer your question... YES, it is possible to allow the user to dynamically hide and show columns in a table widget and it's very very very easy to achieve.
Take into consideration the following example as a demo:
Say you have a datasource with three fields; name, email and assignments. In a new page in app maker, drop a table widget towards the center of the canvas and select that as its datasource. Then add three button widgets on top of the table widget and align them horizontally. Change the text widget of the left button to "Hide Name". Then change the text of the middle button to "Hide Emails" and then change the text of the right button to "Hide Assigns". It should resemble something like this:
Now, click the left label widget inside the table row (not inside the table header), and change its name property to "name". Do similar with the middle label widget and change its name property to "email" and also with the right label widget changing its name property to "assign". Take a look at the example below:
Next, we need to add some logic to the onClick events of our button that will dynamically show and hide the columns. Click on the "Hide Name" button and and the following code to the onClick event:
var visibility;
if(widget.text === "Hide Name"){
widget.text = "Show Name";
visibility = false;
} else {
widget.text = "Hide Name";
visibility = true;
}
var table = widget.root.descendants.Table1.descendants;
table.Table1nameHeader.visible = visibility;
var tableRows = table.Table1Body.children._values;
for(var i=0; i<tableRows.length; i++){
var row = tableRows[i];
row.children.name.visible = visibility;
}
We also need to add similar code to the "Hide Email" button. Click on that button and add the following code to the onClick event:
var visibility;
if(widget.text === "Hide Email"){
widget.text = "Show Email";
visibility = false;
} else {
widget.text = "Hide Email";
visibility = true;
}
var table = widget.root.descendants.Table1.descendants;
table.Table1emailHeader.visible = visibility;
var tableRows = table.Table1Body.children._values;
for(var i=0; i<tableRows.length; i++){
var row = tableRows[i];
row.children.email.visible = visibility;
}
And finally, we do the same thing with the "Hide Assigns" button. Click on it and add the following code to the onClick event:
var visibility;
if(widget.text === "Hide Assigns"){
widget.text = "Show Assigns";
visibility = false;
} else {
widget.text = "Hide Assigns";
visibility = true;
}
var table = widget.root.descendants.Table1.descendants;
table.Table1assignmentsHeader.visible = visibility;
var tableRows = table.Table1Body.children._values;
for(var i=0; i<tableRows.length; i++){
var row = tableRows[i];
row.children.assign.visible = visibility;
}
That should be all. It's time to preview the app. Please do so and the result should be something like this:
I hope it helps!

One more alternative to the solution provided by Morfinismo is rendering dynamic tables. The idea is to render table's header using Grid Widget and to render table's body using List Widget with Grid inside each row. Grid's datasources could be populated using Model's Metadata. More details and screenshots could be found in option #4 in this answer.

Related

How to catch onchange event of radio button that is present in every row of single table in spark ui toolkit

Iam using spark ui table and I have radio button group (Yes and No)and teaxtarea in each row.I have multipe rows.
My requirement is that if click on Yes ,then the textarea should be hidden only in that row.I wrote below code in load
var table = page.ui.get('/tablecv1/Table1');
var radiobtn = table.ui.getSibling('/tablecv1/Table1/Radio_Button_Group1');
radiobtn._instance.input.onchange = function(event){
if(radiobtn.getData() == "yes"){
radiobtn.ui.getSibling("Text_Area1").setVisible(true)
}
else{
radiobtn.ui.getSibling("Text_Area1").setVisible(false,true)
}
}
As of the now the code is working only for the first row.But for the secomnd row,on change of button it is not even going inside that function,the reason may be the control name is same for all.How can I handle this case where I should be able to click radio btn in any row and specific textarea should be hidden
You could pass the target radio button to the inline function. That would be like this:
this.setAreaVisibility = function(radiobtn) {
radiobtn._instance.input.onchange = function(event){
if(radiobtn.getData() == "yes"){
radiobtn.ui.getSibling("Text_Area1").setVisible(true)
}
else{
radiobtn.ui.getSibling("Text_Area1").setVisible(false,true)
}
}
}
Then on "On Change" event of the radio button element you should call this function like this:
me.ui.invoke("setAreaVisibility", me);

dojo enhanced datagrid loses focus after edit

I have an enhanced datagrid that uses a jsonreststore.
I have set the editable cell to auto-save. To do this, I added a onApplyCellEdit property. after successful save (by pressing enter key) the server responds with the new data and my datagrid is updated. however, the focus on the cell just edited loses focus. As a result I cannot use the arrow key to navigate to the next cell, forcing me to use the mouse. Is there any way to regain focus so that I can use the keyboard to navigate after editing?
I have done following code to kind of regain the focus using setTimeout but I think it is not a good solution because if it takes too long for the server to respond the cell will regain focus first and when the response comes in and cell is updated, the cell will lose focus:
var accounts = new EnhancedGrid({
structure: account_layout,
selectionMode: "single",
canSort: function(){
return false
},
onApplyCellEdit: function(inValue,inRowIndex,inFieldIndex){
if(this.store){
this.store.save();
window.setTimeout(function(){
var cells = accounts.layout.cells;
var fieldLocation;
for(var i = 0; i < cells.length; i++){
if(inFieldIndex === cells[i].field){
fieldLocation = i;
break;
}
}
accounts.focus.setFocusCell(cells[fieldLocation],inRowIndex);
},500);
}
}
});
I also tried:
this.store.save().then(function(){ ...});
But it's not working.
EDIT
To clarify question, I added sentence after first sentence of 2nd paragraph.

How do we restrict the length of a combo box control in ASP.NET?

Basically I want that the Title field(Combo Box) should not allow me to enter more than 40 characters.
Can you provide any pointers?
I looks like the control itself does not have that functionality, so you will probably have to write your own version.
You could create a custom control to extend the ComboxBox control. Check out this blog post.
Another idea is to use jQuery to prevent more than 40 characters from being added to the input control the ComboBox control generates:
$(function() {
var comboxBoxControlInput = $("#<%=comboBoxControlId.ClientID%>$TextBox");
$(comboxBoxControlInput).keyup(function() {
limitLenth(this, 40);
});
});
function limitLength(control, length) {
var currentContent = $(control).val();
var currentLength = currentContent.length;
if(currentLength > length) {
$(control).val(currentContent.substr(0, length));
return false;
}
}
Unfortunately it's a bit hacky. You have to get the ClientID of the ComboBox control (<%=comboBoxControlId.ClientID%>) and then append $TextBox to the end in order for jQuery to select the correct control.
Edit:
Another way to select the correct input control is to do this:
$("#<%=comboBoxControlId.ClientId%>").find("input[type=text]");
This selects the first text input within the div the ComboBox control creates.

jqGrid Toolbar CustomButton OnClick: How can I get the parent grid row id?

I am using the jqGrid for ASP.NET MVC, and have a grid with a subgrid. In that subgrid, I have added a button to the toolbar like so:
ToolBarSettings = new ToolBarSettings()
{
ShowRefreshButton = true,
CustomButtons = new List<JQGridToolBarButton>()
{
new JQGridToolBarButton()
{
Text = "Custom",
Position = ToolBarButtonPosition.Last,
OnClick="CustomClick" }
}
},
etc...
}
The CustomClick is a javascript callback, and it fires without any problems, but I am having trouble getting the parent grid row id in the CustomClick callback.
How can I get the parent row id in the CustomClick function?
Thanks, Dennis
The child Grid id itself contains the parentKey. when ever a child grid is created the id of the child grid is ParentGridName_ParentKey_ChildGridName. So you can get the Parent key
Below is the code for custom button :
<CustomButtons>
<Trirand:JQGridToolBarButton ToolTip="Custom button" OnClick="GetParentKey" />
</CustomButtons>
Then inside GetParentKey function you can get the parentKeyID as follows :
function GetParentKey()
{
var GridId = this.id.toString().split('_');
var parentKey = GridId[1];
}
Inside of CustomClick function you has as this the DOM element of the table from which navigator the custom button are clicked. There are no "parent row", but you can get the id of the currently selected row (if any exist) per
var rowid = $(this).jqGrid('getGridParam', 'selrow');
see example from the following answer oder search for another examples to the navButtonAdd method.

How do i know that which button is clicked in flex?

for (iss = 0; iss < listOfProductIds2.length; iss++)
{
// Alert.show(listOfProductIds2[iss]);
var productMain:VBox=new VBox();
var p1:HBox=new HBox();
var l1:Label=new Label();
var b1:Button=new Button();
var spacer:Spacer=new Spacer();
spacer.width=300;
b1.label="Remove";
b1.setConstraintValue("id","");
b1.addEventListener(MouseEvent.CLICK,removeProduct);
l1.text="Product "+iss;
p1.setActualSize(500,500);
p1.addChild(l1);
p1.addChild(spacer);
p1.addChild(b1);
productMain.addChild(p1);
}
function removeProduct(event:MouseEvent):void
{
// How do i know which button is clicked
}
Use event.currentTarget (instead of event.target) because event.target might be the Label component or some styling component within the button, but currentTarget is assured to be the object with which the listener was registered.
To get a handle to the button that was clicked you can just cast the currentTarget to a button.
function removeProduct(event:MouseEvent):void
{
var b1:Button = Button(event.currentTarget);
}
The method setConstraintValue is for setting layout constraints, not setting id. The id property is used by mxml for creating variable names for objects. You can get/set id as you would get/set any other property (say width) - but neither have I seen anyone doing that nor do I see any need to do that in the first place.
event.target should point to the Button you clicked on, shouldn't it ? However you should probably give ids to the buttons to be able to differenciate them (since you create them dynamically.)
Look at event.target.
If ids are assigned dynamically as in the example given b1.id = "button_" + listOfProductIds2[iss]
Then the function that processes the click event would look at the currenttarget, and what I usually do is do a string replace on the part of the id that you know is not dynamic like "button_" with "", which leaves you with the name of the product.

Resources