jquery selector - how to sort the iterated objects - jquery-selectors

Let say there are 3 divs Div1, Div2, Div3 and all have the class "ui-selected"
To iterate the div selection you can use something like below
$(".ui-selected").each(...)
The above iteration, references each div in the same sequence as they are added to the Document.
How do we sort the selection.
For e.g if Div1 represents a value of 30, Div2 represents value of 10 and Div3 a value of 40
the iteration when sorted should be as
Div2 , Div1 and Div3.
Right now the list iterates in the order of how they belong in the Doc model.
Is there a way to sort the jquery selection?

Assuming you have a way to know the "value" of each div, you can use the sort method.
$(".ui-selected").sort(function(a,b){
//sorting logic here
}).each(...);

Related

Given two sets, how can I determine what was added or removed?

let first = { 2, 4, 5, 9 };
let second = { 2, 8, 15, 53, 4 }
//removed = 5, 9
//added = 8, 15, 53
What is the simplest solution to determine what was added or removed?
Just use set differences.
To determine what was added, take the set subtraction
second.subtracting(first)
To determine what was removed, take
first.subtracting(second)
A very simple algorithm for determining the changes is similar to the merge algorithm for sorted lists:
Order both sets
Start iterating both ordered lists at the initial element
In a loop, if the current item from both lists is the same, skip it by moving to the next element of both lists
If the item in the original set is smaller, add it to the list of removed items, and move the original set to the next item
If the item in the new set is smaller, add it to the list of added items, and move the new set to the next item
If you reach the end of one of two lists before the other one, add the remaining elements to the corresponding output list (added or removed).

How to change background color for each two rows in SSRS in a group

How can I write the expression in order to change background color for each two rows in SSRS?
I need something like that:
I tried expression
=IIF(Fields!Type.Value="2016 Submitted" , "LightBlue",
IIF(Fields!Type.Value="2015 Submitted" , "LightBlue",
Nothing))
But because some months dont have values it looks like this:
If I try this expression I get below:
=IIF(RunningValue(Fields!Count.Value, CountDistinct, Nothing) MOD 2 = 1, "White", "PaleTurquoise")
Dance-Henry I tried your code
=IIF(RowNumber(Nothing) Mod 4 = 1 or RowNumber(Nothing) Mod 4 = 2, "Aqua","White")
and this is what i got:
You can select the row in design pane and press F4 to setup property BackgroundColor as =IIF(RowNumber(Nothing) Mod 4 = 1 or RowNumber(Nothing) Mod 4 = 2, "Aqua","White")
Captures are attached. Do it accordingly.
RESULT is something like this
After going thru the link https://blogs.msdn.microsoft.com/chrishays/2004/08/30/green-bar-matrix/
Tested and it works well for the Green Bar Effect for Matrix. I will show it step by step here as for later reference.
Step 1: Create the Matrix and add one more column under the innermost row grouping in your matrix. (ColorNameTextbox here)
Step 2: Select the textbox of ColorNameTextbox and press F4 to setup BackgroundColor property as =Value shown below.
Step 3: Select the textbox of Matrix cell and press F4 to setup BackgroundColor property as =ReportItems!ColorNameTextbox.Value shown below.
Step 4: Drag the inner grouping header (ColorNameTextbox) to be as narrow as possible.
Step 5: Preview Pane to check the result.
If you could add a hidden color_group column and populate it with a new number at each point you want to change the color (in your case 1,1,2,2,3,3,4,4) then you could use something like the following (which works for varying size groups):
IIF(RunningValue(Fields!color_group.Value, CountDistinct, Nothing) MOD 2 = 1, "White", "PaleTurquoise")
I had a similar problem where I could not come up with alternating rows because my data has Column Groups that were the RowNumber(Nothing) method to fail. Learning from all the other posts here this is how I resolved it in steps.
I added the following code into the report properties, that provides a function to get the row number, each time it is called. The function increments the row count each time it is called. >>Right click space around the report >> Properties >> Code. Alternatively go to Code Properties Window, when the report is selected.
Add the following lines:
Public Row_Sum As Decimal = 0
Public Function Lookup_Sum( ) As integer
Row_Sum = Row_Sum + 1
Return Row_Sum
End Function
I added a new column at the beginning of the rows called No. that would calculate and show the row number.Right click the first column >>Insert Column>>Inside Group-Left.
On the expression for the new report add this line of code. Also take a note of the name of the TextBox that will have the No. Value. It will be needed in the next step. In my case the TextBox is called TextBox6 (Properties Window). >>Right Click Cell>>Expression.
Add the code:
=Code.Lookup_Sum()
I highlighted the entire row and went to the Background property and added the following expression to compute the row number.
Add the code(TextBox6 is the name Textbox name noted above):
=IIF(VAL(ReportItems!Textbox6.Value) MOD 2, "LIGHTBLUE", "WHITE")

Listbox multiple selection matlab

I created a listbox and enabled multiple selections. My listbox contain numbers from 1 to 10. When I select 3, 1, and 8, the function always put my selections in alphabetical order (1,3,8). Is there any way I could make it not put my selection in alphabetical order? So if I select 3, 1, and 8 the output of my selection is 3, 1, 8.
Thank you.
For the purpose of this answer I'm assuming you're using matlab-hg2.
From the docs for uicontrol:
'listbox' ... The Value property stores the row indexes of currently selected list box items, and is a vector value when you select multiple items. After any mouse button up event that changes the Value property, MATLAB evaluates the list box's callback routine. To delay action when multiple items can be selected, you can associate a "Done" push button with the list box. Use the callback for that button to evaluate the list box Value property.
From the above we learn that the information on the selected lines is returned in Value. From there, it's a matter of keeping track of what's selected. This can be quite easily done using a persistent variable inside the listbox' Callback as shown in the following example:
function LISTBOX_EXAMPLE
hFig = figure('Units','Pixels','Position', [200 200 100 200],'Menubar','none');
uicontrol(hFig, ...
'Style', 'listbox',...
'Units','Pixels',...
'Position', [20 20 80 150],...
'Max',3,...
'Min',0,...
'String',num2cell(1:10),...
'Callback',#selectionCallback);
function selectionCallback(hObject,~)
persistent previouslyChosenItems
%// Elements were added:
if numel(previouslyChosenItems) < numel(hObject.Value)
previouslyChosenItems = union(previouslyChosenItems,hObject.Value,'stable');
%// Elements were removed:
elseif numel(previouslyChosenItems) > numel(hObject.Value)
previouslyChosenItems = intersect(previouslyChosenItems,hObject.Value,'stable');
%// A different element was selected (single element):
elseif numel(previouslyChosenItems) == numel(hObject.Value) && numel(hObject.Value)==1
previouslyChosenItems = hObject.Value;
end
disp(['Currently selected items (in order): ' num2str(previouslyChosenItems(:)')]);
end
end
Example output:
Currently selected items (in order): 7
Currently selected items (in order): 3
Currently selected items (in order): 3 9
Currently selected items (in order): 3 9 1
Then it's up to you to assign the value of previouslyChosenItems somplace useful.

How to make jbutton sum up the values of my jradiobuttons

I'm making a project in jFrame. It has 15 jRadiobuttons. What I want is a jButton to add the selected jRadioButtons and display the sum in a jTextField. Can anyone help me? I've been doing this for 3 days and cant get it right.
So you have numbers as values of the radiobuttons?
Then try it like this:
When the button is clicked, go through a foreach loop of all radiobuttons.
in the loop, check if they are selected. If they are, you add their value to the Sum.
Is that what you were asking for?
EDIT
You create A List containing all radiobuttons.
In the Listener of the Button you write:
int sum = 0;
//foreach loop
for (jRadiobutton rbutton : rbuttons){
//Check if the button is selected
if (rbutton.isSelected){
sum += rbutton.Value;
}
}
I hope this is good enough explained.
Maybe the Syntax isn't correct, i haven't used java for a while now...

jquery ui sortable temporary element swapping during drag

I need to implement temporary drag replacement in a size-limited jquery ui sortable list.
I have 2 sortable lists:
A "slot" with only 1 spot to hold a single element
A "bucket" that holds several elements from which the user can pick any to fill the "slot"
The user has to drag an element from the bucket into the slot. While the user is holding the element with the mouse over the slot, if the slot is already occupied, the current slotted element should be moved into the bucket to visually make room for the dragged element. Then the user has 2 options:
If the user drops the new element: insert the new element into the slot
If the user cancels the drop: move the previously slotted element back into the slot (as it was originally)
This behaviour should repeat until the user has either cancelled the drag or dropped the element into the slot or the bucket.
To visually limit the slot to a single element, I have limited it to the exact height of a single element and setted its overflow to hidden.
Unfortunately, I have not been able to produce the effect while keeping a single element in the slot at all time.
EDIT 1: Here is an example of what I have so far
$(".slot").bind("sortchange", function (event, ui) {
var slot = $(event.target);
var bucket = $(".bucket");
// Move any element already in the slot (other than the currently
// dragged element) into the bucket
var slotElements = slot.children(".item").not(ui.item);
if (slotElements.length > 0) {
for (var idx = 0; idx < slotElements.length; idx += 1) {
var element = $(slotElements[idx]);
moveAnimate(element, bucket);
}
}
});