Change grid attribute value on runtime in genexus - genexus

How can I change the value of the attribute in a grid on runtime?
For example, I have an IsActive attribute with a boolean datatype in a Transaction and I put it on a Grid in web panel. I want it to display as Text like 'Active' if the value is true and 'Inactive' otherwise.
Here's the screenshot: link

Attributes in WebPanels grids are readonly
You can add a variable in the grid... char(20),
in load code, set something like this:
iif(StaffIsActive, 'Active', 'Inactive')
You are using WW+, here is a help for this:
Grid Variable

Related

Kendo TreeView in grid display 'undefined'

I had this kendo grid demo, and on outletID column, i want to use kendoTreeView with checkbox, so multiple selected outletID possible. But when edit it display undefined result, and the template that display outletName also not working. Appreciate your help
DEMO IN DOJO
Your tree needs dataTextField and dataValueField set.
Your column template doesn't know where to look for the outletName. Kendo supports 1-N relationships, but I'm not aware of N-N.
The data in your template is the current row of the grid. For the first row, that would be {"id":"1","outletID":"LA2,LA3","accountName":"Data1"}. You need to process that data yourself. For instance:
template: "#= (data.outletID) ? data.outletID.split(',')
.map(x => TreeData.find(y => y.outletID == x)['outletName']) : '' #"
For the editor, the value of a dropDownTree is an array. Your row has a string. You need to do two things:
1 . Init the editor's value in the function outletTree:
if (options.model) {
ddt.value((options.model[options.field] || '').split(','))
}
2 . When the dropDownTree's value changes, update your grid row:
change: e => {
const value = e.sender.value();
console.log(value)
options.model.set(options.field, value.join(','))
}
Here's an updated dojo: https://dojo.telerik.com/#GaloisGirl/oYEGerAK . The "Update" button doesn't work yet, probably because the dataSource must support edition. Here is how to do it on local data.

How to select an option in a dropdown based on a value on the model using thymeleaf

I would like to select an option in a dropdown using a value in my Model (org.springframework.ui.Model), I know how to do it with th:object and th:field but what if I don't have an object and only a key/value in the model?
I'm using spring boot 2 and thymeleaf 3.
Thank you.
So if I'm understanding the question correctly you want to display values on your drop-down options first ( so that you could select one of them further) based on the selected Model.?
And May I know how you're selecting the Model , is it from UI ?
For example :--
You have selected a value in a HTML option( Values from your Model ), and based on that Selected Value you want to display the values further on another HTML-option which you can select further.
You don't need th:object and/or th:field to dynamically select a option. Just add your options to the model and use the th:selected attribute.
<select ...>
<option ...
th:each="op : ${myOptions}"
th:value="${op.myValueMember}"
th:text="${op.myTextMember}"
th:selected="${op.myTextMember == 'Chimichanga'}"
>
</option>
</select>

Ternary Conditional Operator not returning true/false

I have a user setting for admins that will show a delete button if they're an admin, and hide it if they're not an admin. What I'd like to say is "If the delete button is visible, the heading of this table column will say "View/Delete". If you're not an admin, the heading will say "View."" I'm also using a JS plugin called jQgrid, which is why the code is in the ColModel block. So far, it's returning true (showing "View/Delete") for everyone, even if they aren't an admin. Any suggestions? Please be nice - I'm new at this :)
, colModel: [
{ name: $(".delete:visible") ? 'View/Delete' : 'View',
The text of the header of the column of the table should have no direct relation with the value of name property of colModel. You can't dynamically change name of any column without recreating of the whole grid.
What you probably need is setLabel method which allows to change the text or attributes on any grid column. For example you can have the column {name: "view", ...} and colNames: [..., "View", ...]. To change the text "View" to "View/Delete" you need to execute
$("#gridid").jqGrid("setLabel", "view", "View/Delete");

Setting a default selected value in DropDownList in MVC3

In MVC3 I have this code at my controller. It retrieves a List of IDs\Names from Installation table and creates a ViewBag
var vs = dba.Installation.OrderBy(q => q.InstName).ToList();
ViewBag.Vessels = new SelectList(vs, "InstId", "InstName");
Now, at my view. I want to render the list in a dropdown list. I used the Html helper that works fine...
#Html.DropDownList("InstId",(SelectList)ViewBag.Vessels, "- Select one -")
I need to set first item in the ViewBag List as a default selected value, instead of "- Select one -" text.
How can I do it?
Thanks in advance!
There's an overload for the SelectList constructor that takes 4 arguments. The last of which is the default selected object. E.g:
ViewBag.Vessels = new SelectList(vs, "InstId", "InstName", selectedValue);
Where selectedValue is an object of whatever type is in your list.
I need to set first item in the ViewBag List as a default selected
value, instead of "- Select one -" text.
Then you need to select the first item in your list (vs) and get it's id and use it as the selecedValue in the SelectList:
ViewBag.Vessels = new SelectList(vs, "InstId", "InstName",
vs.FirstOrDefault().InstId);
You can also create an Helper class for Dropdownlist
It will have a method to set the text as by default text for every dropdownlist in you solution

How can I have a default value in a non required django form field?

class MyForm(forms.Form):
...
my_field = forms.CharField(required=False)
By default, my_field will have None, if it wasn't completed. How can I make it have a default value? Is there any way I wouldn't have to use initial? I don't want it displaying the default value inside the widget.
When you pull the value from the form, set it to the default if it has no value.
my_value = myform.cleaned_data['my_field'] or SOME_DEFAULT_VALUE

Resources