In my Ng-grid cell,i have applied this cell template. i'm getting data but with duplicated regionName.
<select ng-cell-input
ng-options="l.RegionID as l.RegionName for l in regionActivities"
ng-class="'colt' + $index" ng-model="COL_FIELD" ng-input='COL_FIELD' ng-change="activityRegionChange(row)" ng-show='!isRoomRequestInProgress'></select>
{{COL_FIELD}}
is there any way to prevent duplicates?
What you need to do is building or reusing a unique filter
<select ng-cell-input
ng-options="l.RegionID as l.RegionName for l in regionActivities | unique:'RegionName'"
ng-class="'colt' + $index" ng-model="COL_FIELD" ng-input='COL_FIELD' ng-change="activityRegionChange(row)" ng-show='!isRoomRequestInProgress'></select>
Related
Is it possible to either extract the text portion of a select tag after it is passed to a controller or do something else crafty with rails to get the value between the <option></option> tags?
My raw html is simple:
<select>
<option value></option>
<option value="5">I have a small problem</option>
<option value="10">I have a big problem</option>
<option value="15">I have a massive problem</option
</select>
I'm converting the selected value to integers in my controller which triggers other system calls (such as routing to the correct support person), however, I'd like to be able to also save the text portion into the user's profile for tracking (i.e. `user.issue = "I have a small problem").
Shy of creating some hidden fields and using Javascript, is there another way to get or include the text value when it passes to the controller?
Here is some advice which is going to be very general since you don't give a lot of specifics in your question. Yes, the HTML should be "the same" no matter what but really it does matter how you create it because that reflects how it integrates into the rest of your app.
I would create a table in the DB called severity with rows something like this:
id | text | val
1 | 'small' | 5
2 | 'big' | 10
3 | 'massive' | 15
Now instead of doing translations elsewhere like you imply ("I'm converting the selected value to integers in my controller which triggers other system calls") you can use things like:
problem.severity.text
=> 'massive'
problem.severity.val
=> '15'
Using relationships like has_one, belongs_to, etc. you can then leverage these values or words anywhere in your application. Something as simple as:
<%= f.collection_radio_buttons :user_id, Severity.all, :id, :text %>
I should recommend you to use select2 for multiple values selecting, select2-rails is its integration with rails. It's pretty simple. Give it a shot.
Is there a way to use the Live Binding Designer to concatenate 2 database fields to a component?
For example I have a MemTable for client, I want to concatenate the FirstName and LastName (fullname) to a label.
If there is a way to do that, I understand that the binding will be in one direction only (Database fields --> ComponentProperty).
The easyest way to do with LiveBinding, is to use the CustomFormat property of the LinkFillControlToField :
Just use this format text as the example is the question:
Self.Owner.FirstName.text + " " + Self.Owner.LastName.text
For something simple like this...you can use the AfterScroll Event of your Dataset
if Dataset.Active and (Dataset.RecordCount > 0) then
label1.Caption :=Dataset.FieldByName('FirstName').AsString + ' ' + Dataset.FieldByName('LastName').AsString;
Given a loop like:
#For Each x In item.PostCategory
Dim cats = x.CategoryName & ", "
#Html.ActionLink(cats,
"PostsByCategory", "Posts", New With {.Category = x.CategoryName.ToSeoUrl,
.Page = Nothing}, Nothing)
Next
I need to remove only the last comma and space - everything I have tried removes the commas and spaces in the middle as well as the end. The loop renders categories and I want them separated by a comma and space but do not need or want the trailing comma and space. Each category needs to be a separate link so string.join won't work. I tried trim.substring - that removes the commas in the middle. TrimEnd did not work. I have searched and have not found a solution.
Instead of World, Science, - i want World, Science
You can try to check if x is the last item in PostCategory. If it is true, then append an empty string, else append comma and space :
Dim cats = x.CategoryName & IIf(x.Equals(item.PostCategory.Last()), "", ", ")
There's many different ways to solve this problem. You'll have to determine the best way. Simply, you can just not use a foreach and do a simple for instead. Then you can easily tell if you're on the last item by comparing the index with the count and conditional show or not show the comma based on that.
Alternatively, you can construct a list of the string values this code would otherwise render directly to the page and then use string.Join to join the list items separated by ", ". string.Join never appends the delimiter to the end, so that fixes your problem.
You could also go fancier with some sort of editor template or partial view or even create a HtmlHelper extension. If just depends on how you want to handle it.
I have two cases. The preliminary code:
open Microsoft.Office.Interop.Excel
let xl = ApplicationClass()
xl.Workbooks.OpenText(fileName...)
let wb = xl.Workbooks.Item(1)
let ws = wb.ActiveSheet :?> Worksheet
let rows = string ws.UsedRange.Rows.Count
First, I try the following to sort:
ws.Sort.SortFields.Clear()
ws.Sort.SortFields.Add(xl.Range("A8:A" + rows), XlSortOn.xlSortOnValues, XlSortOrder.xlAscending, XlSortDataOption.xlSortNormal) |> ignore
ws.Sort.SortFields.Add(xl.Range("H8:H" + rows), XlSortOn.xlSortOnValues, XlSortOrder.xlAscending, XlSortDataOption.xlSortNormal) |> ignore
ws.Sort.SetRange(xl.Range("A7:I" + rows))
ws.Sort.Header <- XlYesNoGuess.xlYes
ws.Sort.MatchCase <- false
ws.Sort.Orientation <- XlSortOrientation.xlSortRows
ws.Sort.SortMethod <- XlSortMethod.xlPinYin
ws.Sort.Apply()
This results in "The sort reference is not valid. Make sure that it's within the data you want to sort, and the first Sort By box isn't the same or blank.".
Then I try the following to sort:
ws.Range("A7:I" + rows).Sort(xl.Range("A8:A" + rows), XlSortOrder.xlAscending,
xl.Range("H8:H" + rows), "", XlSortOrder.xlAscending,
"", XlSortOrder.xlAscending, XlYesNoGuess.xlYes,
XlSortOrientation.xlSortRows) |> ignore
This results in my columns being rearranged, though I don't see any logic to the rearrangement. And the rows are not sorted.
Please tell me what I'm doing wrong.
I haven't figured out why the first Sort attempt doesn't work. But I checked out the documentation on the second Sort. Using named parameters and dropping all but necessary parameters, I came up with the following:
ws.Range("A8:H" + rows).Sort(Key1=xl.Range("A8:A" + rows), Key2=xl.Range("H8:H" + rows),
Orientation=XlSortOrientation.xlSortColumns) |> ignore
The default Orientation is xlSortRows. I interpret this as sorting the rows, the normal, default, intuitive sort that Excel does when one sorts manually. Oh no. If you want the normal, default, intuitive sort that Excel does when one sorts manually, specify xlSortColumns.
The first Sort doesn't work because you're probably trying to sort a table (judging by property Header set to XlYesNoGuess.xlYes) by columns located on A and H. In this case you can only sort using "Sort top to bottom"(xlSortColumns).
You can also convince yourself by trying this in Excel first and see what options are available:
1) Select the range you want to apply sorting (e.g. in your case "A7:I" + rows)
2) Click on "Data" menu -> "Sort & Filter" task pane -> Sort
3) Add/Delete columns/rows by using "Add Level"/"Delete Level" buttons
4) Then you can select whatever level you want and click "Options..." button and you will see your available "Sort Options".
You will notice that in case of a table you will have only one available option for "Orientation", which is "Sort top to bottom"
xlSortColumns - sorts by columns (meaning rows are sorted based on those columns)
xlSortRows - sort by rows (meaning columns are sorted based on those rows)
Is there any better approach than what I am currently doing here:
MVC Controller action creates a select list as:
ProductsDDL.Select(rp => new SelectListItem
{ Value = Model.RawMaterialID.ToString() + "," + plant, Text = Model.FinishedProductName });
And HTML rendered as:
<select id="Products" name="Products">
<option value="3,PLANT1">Finished Product1</option>
<option value="4,PLANT2">Finished Product2</option>
<option value="7,PLANT3">Finished Product3</option>
</select>
On selection change, I use Jquery $.GetJSON to populate another drop down list. The reason I am concatinating PlantID with RawMaterialID is to avoid long query processing time.
On Post to action(string RawIDPlantID), I use Split(',') to get RewMaterialID & PlantID
Other options are to use session to hold PlantID or input hidden field in MVC view.
I typically stay away from using commas as a delimiter in values that represent a single entity, and save the commas delimiting a list of multiple ids. In cases such as yours, I end up using an underscore. Then, should I need to comma separate a list of the IDs, it's easier on the eyes and to parse. But that's completely subjective and up to you, as the developer.
For example
3_PLANT1,4_PLANT2,7_PLANT3
is easier to eyeball
3,PLANT1,4,PLANT2,7,PLANT3
And that was as much criticism as I could muster about your code. The rest of it I'd use, and have used in the past.