Confused about DropDownListFor - asp.net-mvc

I am retrieving a few bunches of int/string pairs that I want to generate dropdown lists for, and subsequently use these filter a collection of items.
Currently, I create these filters as SelectLists in the Controller this way:
foreach (int key in filterChoices.Keys)
subFilter.Add(new SelectListItem {Value = key.ToString(), Text = filterChoices[key]});
where "filterChoices" holds the id (int) and text (string) as key, value pairs.
Then I'm a bit confused as to what to do. I have tried to put together bits and pieces from various examples, but don't really understand what's going on.
This is what I'm trying currently:
Html.DropDownListFor(m => m.SelectedDimension, new SelectList(Model.DimensionFilter, "Text", "Value", Model.DimensionFilter.First().Text));
The first part, I'm not really sure what its use is, but I am assuming it's the property whose change controls what is being selected in the list? Something along those lines? So I'm trying to set this int to some arbitrary value that corresponds to one filter entry, but to no avail.
No DropDown shows up.

just use
#Html.DropDownListFor(m => m.SelectedDimension, Model.DimensionFilter)
if you already created a selectList

Related

How to sort on hidden or data-attribute value in textSorter

I have a "name" column in a table that contains a persons full name (ie. first+last name). The objective is to sort the column based on the person's last name first, then first name. My initial naive approach for the textsorter function was
function (a, b){
const aSplit = a.split(' ');
const bSplit = b.split(' ');
const aReverse = aSplit[1] + aSplit[0];
const bReverse = bSplit[1] + bSplit[0];
return aReverse.localeCompare(bReverse);
}
Unfortunately, some of the names I have to sort have extraneous spaces in them, potentially in either the first name or last name field. So I have to support this in my sorting.
I am currently only using the combined first+last name string for display and sorting but I have access to the seperate name strings as well as a preformatted lastname, firstname version. I'd like to attach either of these to the <th> tags as a data attribute or something like that and sort using that instead of the actual value but I'm not sure how to go about accessing those attributes from within the textsorter function.
Maybe try this - when you build the table HTML, add the last name + first name into a data-text attribute of the cell. Tablesorter will automatically use that attribute over the actual text within the cell. See textAttribute option to allow changing that attribute name.

How do i remove rows based on comma-separated list of values in a Power BI parameter in Power Query?

I have a list of data with a title column (among many other columns) and I have a Power BI parameter that has, for example, a value of "a,b,c". What I want to do is loop through the parameter's values and remove any rows that begin with those characters.
For example:
Title
a
b
c
d
Should become
Title
d
This comma separated list could have one value or it could have twenty. I know that I can turn the parameter into a list by using
parameterList = Text.Split(<parameter-name>,",")
but then I am unsure how to continue to use that to filter on. For one value I would just use
#"Filtered Rows" = Table.SelectRows(#"Table", each Text.StartsWith([key], <value-to-filter-on>))
but that only allows one value.
EDIT: I may have worded my original question poorly. The comma separated values in the parameterList can be any number of characters (e.g.: a,abcd,foo,bar) and I want to see if the value in [key] starts with that string of characters.
Try using List.Contains to check whether the starting character is in the parameter list.
each List.Contains(parameterList, Text.Start([key], 1)
Edit: Since you've changed the requirement, try this:
Table.SelectRows(
#"Table",
(C) => not List.AnyTrue(
List.Transform(
parameterList,
each Text.StartsWith(C[key], _)
)
)
)
For each row, this transforms the parameterList into a list of true/false values by checking if the current key starts with each text string in the list. If any are true, then List.AnyTrue returns true and we choose not to select that row.
Since you want to filter out all the values from the parameter, you can use something like:
= Table.SelectRows(#"Changed Type", each List.Contains(Parameter1,Text.Start([Title],1))=false)
Another way to do this would be to create a custom column in the table, which has the first character of title:
= Table.AddColumn(#"Changed Type", "FirstChar", each Text.Start([Title],1))
and then use this field in the filter step:
= Table.SelectRows(#"Added Custom", each List.Contains(Parameter1,[FirstChar])=false)
I tested this with a small sample set and it seems to be running fine. You can test both and see if it helps with the performance. If you are still facing performance issues, it would probably be easier if you can share the pbix file.
This seems to work fairly well:
= List.Select(Source[Title], each Text.Contains(Parameter1,Text.Start(_,1))=false)
Replace Source with the name of your table and Parameter1 with the name of your Parameter.

Table converter integer to image

I am fairly new to Vaadin and am creating a small application. Here I display a table with some columns. In one of the columns I have an integer which, depending on its value, I wish to show an image in that cell.
I have been looking onto table converters but have not find what I am looking for. Could someone help me on the road to get this to work?
Thanks!
You can accomplish this using a column generator.
table.addGeneratedColumn("imageNr", new Table.ColumnGenerator() {
#Override
public Object generateCell(Table source, Object itemId, Object columnId) {
Integer i = (Integer) source.getItem(itemId).getItemProperty("imageNr").getValue();
Resource res = getImageResource(i); // get the resource depending the integer value
return new Image(null, res);
}
});
The column id "imageNr" on the first line doesn't have to be the same as the item property id, but if it is it replaces the integer column in the table and also makes this column sortable according to the underlying integer value.

rails combine parameters in controller

Hopefully this is a little clearer. I'm sorry but I'm very new to coding in general. I have multiple tables that I have to query in succession in order to get to the correct array that I need. The following logic for the query is as follows:
this gives me an array based upon the store :id
store = Stores.find(params[:id])
this gives me another array based upon the param .location found in the table store where that value equals the row ID in the table Departments
department = Departments.find(store.location)
I need to preform one last query but in order to do so I need to figure out which day of the meeting is needed. In order to do this I have to create the parameter day_of_meeting found in the table Stores. I try to call it from the array above and create a new variable. In the Table Departments, I there are params such as day_1, day_2 and so on. I need to be able to call something like department.day_1 or department.day_2. Thus, I'm trying to actually create the variable by join the words "department.day_" to the variable store.day_of_meeting which would equal some integer, creating department.day_1...
which_day = ["department.day_", store.day_of_meeting].join("")
This query finds uses the value found from the variable department.day_1 to query table Meeting to find the values in the corresponding row.
meeting = Meeting.find(which_day)
Does this make my problem any clearer to understand?
findmethod can only accept parameters like Meeting.find(1) or Meeting.find("1-xx").
so, what you need is Meeting.find(department.send("day_" + store.day_of_meeting.to_s))
Hope to help!

Trouble adding item to a list with a lookup value

I am adding a new item to a list in SharePoint 2007. One of the columns is a lookup into another list. Here is the code:
li["LOOKUP"] = new SPFieldLookupValue(1,VALUE);
The entry in the list isn't correct and is always using the first value in the other list. When I look at the value of li["LOOKUP"] in the debugger all I get is "1".
VALUE is in the other list and it is the first column.
When adding items to a list only the id of the element from the list being looked up needs to be provided. It was always adding the first element because I always passed in "1". The following code looks up the value and then gets its id and passed this to the field:
SPListItemCollection lookup = LIST.GetItems(qry);
li["LOOKUP"] = lookup[0][SPBuiltInFieldId.ID].ToString();

Resources