How to update the rows of a table using dialog box - sapui5

I have been going through the below Plunker,
plunker link here
Here If I try to edit , the new record is added above instead of updating the current ,
How can I update the current edited row for the same example instead adding a new one?
I have tried deleting the row and update the new in the deleted place , but this idea is not correct tmk
Any guiding links or any help is much appreciated ....TIA

From your code I understand you want to update the model (variable aData). It would be a better idea to use data binding but if you want to edit it you can use:
aData.map(function(item) {
if (item.ID==id){
item.Name = name;
item.Age = age;
item.Salary = sal;
}
return item; });
This is probably not the efficient way to do it and it consider you have unique ids.
Also don't use the function unshift() because it add new value (doesn't update the existent).The record is added above because you actually add a new element (see link).

You should try to work with data binding rather than manually extracting and inserting your values:
https://sapui5.hana.ondemand.com/1.28.33/docs/guide/91f0ca956f4d1014b6dd926db0e91070.html
Nevertheless, if you do want to edit a property of an item in your array, you can edit it as follows:
array[index].property = "new value";

Related

How to remove a piece in a string

So I am making a quest system, and I want to randomly choose a quest, but i dont want it to choose the same one again.
Here is the piece on code for the string.
I cant find any good answer.
This is a more simple line of code.
string[] QuestChoose = new string[] {"Quest1", "Quest2", "Quest3"};
3 methods come to mind:
Convert to a List and call Remove().
Write null into the array after having read the quest and when selecting a quest, always search for the next suggestion if null was selected.
Keep a separate data structure like a HashSet<int> where you add the index in the array whenever a quest has been used. Then check for Contains on your ID when selecting.
You really ought to use lists if you want to dynamically add/remove elements from your set.
Instead of:
string[] QuestChoose = new string[] {"Quest1", "Quest2", "Quest3"};
try using:
List<string> QuestChoose = new List<string> { "Quest1", "Quest2","Quest3"};
You can add elements by calling QuestChoose.Add("Quest4");
Or remove an element by calling: QuestChoose.Remove(ItemNumber);
Where as "ItemNumber" is the index of the string you want to remove. For example; Calling QuestChoose.Remove(0); will remove the first item in the list, which in this case would be "Quest1"

Create absolute link with specific value of cell in table view

I want to render a absolute link in table from value of cell but I got a relative link instead.
Here is my configuration:
What I got when click on cell:
http://10.93.9.209:3000/http%3A%2F%2F10.131.227.253%2Fjob%2FPerformance%20Testing%20Pipeline%2Fjob%2Fstable%2F21%2F
In Grafana 7 (new table panel) it's ${__data.fields[2]} where number is column index.
This is a change introduced in one of the new Grafana versions. If you want an absolute URL, you must use ${__cell:raw} instead of ${__cell}. Reference
If you want to reference another column when clicking:
This is possible, I am using 9.1.7 and originally used the old table; however, after migrating noticed the same issue. That said, I found a way to make this work:
Add the ID column that you want to hide; example simID
If the column is the first column, say 0; then use:
var-whatever=${__data.fields[0]}
Now, override the column, field with name: simID Add option ‘Hide in Table’ and turn on
I also had to format the number, e.g. remove decimals & set unit to standard
Hope that helps someone… took me a good 2 hours to figure.
Btw, it also works on graphs and you do not have to hide; aka reference your original query in the datasource and add a data link with the same options.
What result do you get if you try $__cell_2?
The syntax above no longer works. The value is now ${__value:raw}
$__cell_2 above solution worked for me.
With the new table panel introduced in Grafana either ${__cell} or ${__cell:raw} do not work for this now.
You must use ${__value:raw}

how to get the already selected value of dropdown protractor

I have a select tag with some options under it . I select one value out of those along with other field values and move to next page. Once I return to previous page I want to check whether the dropdown value is same as that I selected. How can I get the already selected value using protractor. Can someone please help.
Following #Grasshopper's comment, I read this, and the following worked for me:
expect(element(by.xxxxxx('xxxxxxx')).$('option:checked').getText()).toEqual('xxxxxx')
var dropdownval=element(by.xpath/css("Xpathofdropdown/cssofdropdown")).element(by.css('option:checked')).getText();
console.log(dropdownval);
The following code helps me to resolve the issue,now the variable contains the value of the dropdown selected
var dropdownval=element(by.xpath("XpathOfDropdown")).element(by.css('option:checked')).getText();
console.log(dropdownval);
First select the input, then select the option using css, with the option:selected tag:
var selected = element(by.css('#ID_OF_THE_SELECT option:selected'))

How to get user's input from WicketStuff's TinyMCE

Pretty straight-forward question, but I can't find this anywhere. I'm using WicketStuff's TinyMCE to make a Rich Text Editor in my application, and can't find anywhere how to get the input from the text area. For brevity's sake, the following is a simplified version of the code I'm using.
private String input;
...
TinyMCESettings settings = new TinyMCESettings(TinyMCESettings.Theme.simple);
TextArea<String> textArea = new TextArea<String>("editor", new PropertyModel<String>(this, "input"));
textArea.add(new TinyMceBehavior(settings));
form.add(textArea);
Using this, I would expect the usual manner to simply use my String 'input' since it's set as the model. This always results in null as the model isn't being updated.
I tried using the auto-save plugin in case it was expecting the save button to be clicked (which doesn't update the model either), and neither worked. The only thing I've been able to do to get the user's input is to add a HiddenField, with a new model, and make a JavaScript call like
document.getElementById('hiddenField').value = tinyMCE.get('editor').getContent();
but this has led to other problems with trying to call the JS in the desired place and to get it to work properly. I feel this shouldn't be necessary anyways, as surely someone must have implemented a method to get the contents of the text area being used.
Any help would be greatly appreciated.
Thanks to a blog post at Nevermind Solutions, the way to get the model updated is to add the following JavaScript to the form's submitting button:
onclick="tinyMCE.triggerSave(true,true);"
My text area is inside a panel with the button outside of the panel, so it doesn't directly work for me. The trick was to add the JavaScript call to the button's onSubmit, move the logic into the onAfterSubmit, and to make the button MultiPart so that it could call the save trigger before doing the other logic associated to the model.
Hope this might help some others in the future.
You have to add a modifier to the submit button so that the model can update.
AjaxButton btnSubmit = new AjaxButton("btnSubmit", new Model()) {
#Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
doSomething();
}
};
btnSubmit.add(new TinyMceAjaxSubmitModifier());
Have a look here for more info

Dynamic JQuery date picker code

I need to create dynamic filter that adds/removes rows dynamically.
It contains a drop-down box. Depending upon the drop-down box value selected, I create a dynamic <TD> that may have a text field or drop-down list.
If it's a text field, then I have to add date picker for that text field.
I have done this, except date picker for dynamically generated text field.
If you're creating 100 rows, the text fields' names should be same for all rows.
How to add datepicker for dynamically generated text field?
I had the same issue.
You would need to rebind the DatePicker to the dynamically added row.
The date picker associates a hadDatePicker Class to the dynamic row.
So you would need to remove that and rebind.
Something like this -
jQuery('.date-pick').removeClass('hasDatepicker').datepicker({
dateFormat: 'mm-dd-yy'
});
Regards,
Tina Agrawal
Actually i did use the solution provided by #Tina Agrawal But since now, when i select a date from the calendar, i click again and re-select. If i click on next month, it will go to 1900-01-01.
Well it was so strange...
After two hours of trial and errors and research.
i simply did:
$('.date-pick').live('click', function(){
$('.date-pick').datepicker();
});
Well it works.
I had the same issue and solved it in a different way. Although I am not very sure why is it working as I am very new to jquery. I wrote the following and it iterates the entire set of controls having the class "class_date" and rebinds the datepicker control to it.
$(".class_date").removeClass('hasDatepicker').datepicker();
Tirst add a class attribute as "date" to your input or div.
After dynamically add a text input to have to recall $('.date').datePicker() again to bind datePicker to new inputs or div.
I had a similar problem in that when dynamically adding new rows to my table the Date Picker fields in the new rows (any row added to the DOM dynamically) were all updating my initial rows Date Picker fields.
Removing the hasDatepicker class as suggested above was not enough to solve my issue, probably as I was using .clone() to create my dynamically added rows.
The solution when cloning rows was to remove the cloned input fields, re-create them, add them to my newly cloned table row and THEN re-initiate the Date Picker
For example:
//Remove exisiting cloned input fields
new_row.find("td.date input").remove();
//Create new input fields and append to table td
var date_tds = new_row.find("td.date");
$('<input />', {"name":"gStartDates["+n_array_pos+"]","type":"text"}).appendTo(date_tds[0]);
$('<input />', {"name":"gEndDates["+n_array_pos+"]","type":"text"}).appendTo(date_tds[1]);
//Re-initiate datepicker on the input fields
new_row.find("td.date input").datepicker({
dateFormat:"dd-mm-yy",
minDate:StartDate,
maxDate:EndDate
});
Use JQuery Live to access the dynamically created DOM.
http://api.jquery.com/live/
The you can attached the picker.
http://jqueryui.com/demos/datepicker/
one should use ".on" instead of live - see
http://api.jquery.com/on/