jquery-plugin, Select2 4.0.1, how to remove auto sorting in multiple options selection [duplicate] - jquery-plugins

This question already has answers here:
Select2: How to prevent tags sorting
(3 answers)
Closed 2 years ago.
I am using jquery-plugin, Select2 v4.0.1. In my project, by default the plugin sorts the multiple options selection but I don't want the options to be sorted. Any one please help.

I do this, and it works perfectly for me.
function disabledAutoSortSelect(id_select2) {
$("#" + id_select2).off('select2:select');
$("#" + id_select2).on("select2:select", function (evt) {
let element = evt.params.data.element;
let $element = $(element);
$element.detach();
$(this).append($element);
$(this).trigger("change");
})
}

Related

D3.js Visualizations from Local Files

I have a mostly working code that can load one record, but I'm not sure how to expand it. The closest that I've been able to get is to pull 1 record column names from a csv based on the logic from this bl.ocks code snippet.
How can I modify the function below to pull an entire dataset rather than just one record?
By modifying code from the bl.ocks code, below is what I've been able to achieve. But I'm still having trouble looping the second function into pulling every row. In R, I could do something like rowtoHTML(0:length(data))
var rowToHtml = function( row ) {
var result = "";
for (key in row) {
result += key + ": " + row[key] + "<br/>"
}
return result;
}
var previewCsvUrl = function( csvUrl ) {
d3.csv( csvUrl, function( rows ) {
d3.select("div#preview").html(
"<b>First row:</b><br/>" + rowToHtml( rows[0] ));
})
}
d3.select("body")
.append("div")
.attr("id", "preview")
.style("margin", "5px")
previewCsvUrl("Test.csv")
This question has been asked before. I've tried to do my due diligence by reading through similar questions, but was not able to use the recommended solution based off of my technology constraints or due to inexperience with Javascript. The sample code I've used comes from a trimmed version of this bl.ocks code: http://bl.ocks.org/hlvoorhees/9d58e173825aed1e0218
Edit - I understand that hosting a file locally is the right move, but its not an option for me (hence this approach). Python has been recommended for local hosting, but I'm unable to install it on my machine at this time. I'm working with Edge and IE as my two browser options. I really appreciate the help!

Applying change event on j-Query Data-Table Search Box?

I have j-Query data-table with many records and I have builtin search-box. What I am trying is to sum all values in all the tds which have class="amount". It's happening succesfully. Now, the problem is search box. I want to sum the values of tds with class name amount which are only visible. I tried many ways but nothing worked Following is my code:
var salaryTable = $('#tblSalary').DataTable();
salaryTable.on('search', function () {
var sum = 0;
$(".amount").each(function() {
var value = $(this).text();
if(!isNaN(value) && value.length != 0) {
sum += parseFloat(value);
}
});
alert(sum);
});
This logic is not working as expected. How can I solve this or What am I doing wrong? Is there any better approach?
Update: The problem is when I search something it gives me total of visible and invisible records. When I clear the search box with backspace, it gives me total of all records where were visible before.
If you only want visible elements with class amount you could use the jQuery :visible selector
$(".amount:visible").each(...)
jQuery docs https://api.jquery.com/visible-selector/

Swift Programming: Evaluate value in a string [duplicate]

This question already has answers here:
Swift - Resolving a math operation in a string
(4 answers)
Closed 8 years ago.
My question is on SWIFT/COCOA programming. I want to evaluate the content inside a string. For example, I have
var1 = "2 + 3"
Is there any inbuilt function in SWIFT/COCOA that can evaluate content in var1 and return 5. I tried what I could understand from string interpolation but that is not helping
var myNum = "45/30"
var myNum2 = "sin(30)"
var myNum3 = "\(Float(myNum) * Float(myNum2))";
error: could not find member 'convertFromStringInterpolationSegment'
Also, got another question.. How do I detect Return key pressed in SWIFT? Any trigger similar to "func applicationWillTerminate(aNotification: NSNotification) "
For your second question, assuming you're using a textField, you can use the delegate method:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
This method is executed when the return key is pressed. If don't want to hide the keyboard, you need to return NO from this function at the end.
If you're using a textView, you can refer to this thread. You implement the textView:shouldChangeTextInRange:replacementText: method of UITextViewDelegate and in that check if the replacement text is \n.

How to 'Remove sorting' from ExtJs Grid (2.3.0) [duplicate]

This question already exists:
'Remove sorting' from ExtJs Grid (2.3.0)
Closed 8 years ago.
I have asked this question before two months but did not get an answer or even a comment/reply. So posting it again
I have an ExtJs grid having sort functionality. (ExtJS 2.3.0)
I am sorting the columns as follows-
sort: function (colName, direction) {
//
// Some sort logic
//
this.fireEvent("datachanged", this);
}
This is working fine. The columns get sorted successfully.
Now I Have a button above my grid called 'Remove Sort'. On click of this button, I want to remove the applied sorting.
I tried-
removeSort: function (colName, direction) {
// some logic
//
store.sortInfo = null; // This will remove the sortinfo (working as expected)
grid.saveState(); // Saves the sort state (working as expected)
this.fireEvent("datachanged", this);
}
In above code store.sortInfo = null; removes sortinfo and saves the state. But here "datachanged" is not firing. Means, it do not refreshes the grid on 'Remove sort' button.
I know I can use reload() function of grid but here I dont want to reload the grid. I want it should refresh the grid instantly just like it does when I sort the columns.
Please suggest a solution.
In removeSort try not to use keyword this but use direct references to the store object, eg. store.fireEvent("datachanged", store );

Sorting datagrid by two columns removes the sort arrow [duplicate]

This question already has answers here:
Flex: Database driven DataGrid: arrows disappearing
(3 answers)
Closed 4 years ago.
I'm using Flex version 3.6 and I have a requirement to sort a data grid by two columns. When I click on a column header, the sort arrow displays over it.
What I'm trying to do now is when I click on 1 particular column, it will sort on two columns. That part's working.
But I've noticed that the sort arrow indicator that usually appears over a sorted column has disappeared. I'm using a subclass of DataGrid, so after I sorted, I tried to use placeSortArrow()but I noticed in DataGridHeader.as that sortArrowis null.
protected function headerReleaseListener(event:DataGridEvent):void
{
if(event.columnIndex == 0)
{
event.preventDefault();
var sort:Sort = new Sort();
sort.fields = [new SortField("#name",true, true), new SortField("#address",true, false)];
ArrayCollection(this.dataProvider).sort = sort;
ArrayCollection(this.dataProvider).refresh();
}
}
What I'd love to have is to specify on which column the sort arrow should appear on, whether a column is sorted by 1 or more columns. Does anyone know if this is possible?
I found the answer to the disappearing sort arrows from another question: Flex: Database driven DataGrid: arrows disappearing in a question answered by ili and adapted it to suit my code.
Because there were two columns sorted, the internal sortIndexwas -1 and consequently the sortArrow was null.
By picking a column to display the sort on (I used the primary sort column) and setting a sortIndex and direction, the sortArrownow appears.
protected function headerReleaseListener(event:DataGridEvent):void
{
if(event.columnIndex == 0)
{
event.preventDefault();
var sort:Sort = new Sort();
sort.fields = [new SortField("#name",true, true), new SortField("#address",true, false)];
ArrayCollection(this.dataProvider).sort = sort;
ArrayCollection(this.dataProvider).refresh();
mx_internal::sortIndex = event.columnIndex;
mx_internal::sortDirection = (mx_internal::sortDirection == null || mx_internal::sortDirection == "ASC") ? "DESC" : "ASC";
placeSortArrow();
}
}

Resources