how to use scrollx in shiny DT (renderDataTable) - datatable

I want use scrollx options in shiny DataTable since there are many field.
(refer : https://datatables.net/examples/basic_init/scroll_x.html)
How can i use? I cant'n find any examples.

I found! in mainPanel unable work in Shiny Dashboard
Just add options list like bellow
output$actCam <- renderDataTable({
datatable(summaryDay[campaignid %in% act_idx,],
options = list(scrollX=TRUE, scrollCollapse=TRUE))
})

Related

How to get the selected index from a dropdown menu in d3

I have a dropdown menu in d3.js, and I would like to get the index from the selected option. It's a list of a bit more than 50 flight companies, and right now I have this :
function choixCompagnie(){
let compagnieChoisie = d3.select(this).property('value')
}
This function activates whenever there is a change on the drop down, like so :
d3.select("#selectCompagnie")
.on("change",choixCompagnie)
The property('value') means that for instance if I click the first line of my drop down menu, which is Aer Lingus, my compagnieChoisie variable will get the value Aer Lingus instead of 0.
I need it because I then need to access some properties company by company, and my objects are in an array. So in my database I need to access the properties like this data[index].randomProperty and not like this data["Company Name"].randomProperty, since the company name is already a property.
I don't know if this makes sense, sorry if I'm using the wrong terms I'm fairly new to coding.
Thanks for the help !
edit : here is a working example http://blockbuilder.org/ArnaudStephanUNIL/a18332a561579eb929091faaff91fb6f, where the drop down gets the value but not the index
You should access your data like this:
function choixCompagnie(){
let compagnieChoisie = d3.select(this).property('value')
console.log(data.find(d => d.compagnie === compagnieChoisie).accidents);
}
I found a better, easier way to get the index from a drop down menu :
<select id="selectOptions"></select>
Once you initialized your drop down menu, you simply have to do this :
var options = ["option1","option2"];
options.forEach(function(d,i){
d3.select("#selectOptions")
.append("option")
.attr("value",i)
.text(d);
})

How to change the Sorting order in SharePoint 2010 List view Web Part when Group by is applied?

Scenario:
I have created one custom list in my SharePoint 2010 Environment.
In this list, there is one choice column named Status and its values are New,Open and Closed.
On a page I have setup one view and applied Group By using this Status column.
Problem
View is rendering as shown in below image:
I want to change the order of this Status column and it should be rendered in this Sort Order : New, Open and Closed.
If I use Ascending Order it will be displayed as shown in above image and if I use Descending Order then it will be displayed like: Open, New & Closed.
Can any one help me how can I get the requested Sorting for this column? Is there any alternative way to meet my requirement?
Thanks in advance!
I searched on google and tried to find a solution but didn't find any proper solution. As far as I understand, OOTB it won't be possible to apply custom orders for the column which was used for grouping. You can sort them in Ascending order or Descending order only.
But any how, I found a patch and I was able to meet the requirement using JQuery. I applied below JQuery code on the Page, it was working like a charm:
JQuery Code
$("table[summary='GTSRequests']").each(function(){
var tbodyGroupCol = $(this).find("tbody[id*='GroupByCol']");
var grpNew = $(this).find("tbody[groupstring='%3B%23New%3B%23']");
var grpOpen = $(this).find("tbody[groupstring='%3B%23Open%3B%23']");
var grpClosed = $(this).find("tbody[groupstring='%3B%23Closed%3B%23']");
if(grpNew.length > 0){
var strGrpNewId = grpNew.attr("id").replace("titl", "tbod") + "_";
grpNew.insertAfter(tbodyGroupCol)
$("#" + strGrpNewId).insertAfter(grpNew);
}
if(grpOpen.length > 0){
var strGrpOpenId = grpOpen.attr("id").replace("titl", "tbod") + "_";
grpOpen.insertAfter("#" + strGrpNewId);
$("#" + strGrpOpenId).insertAfter(grpOpen);
}
if(grpClosed.length > 0){
var strGrpClosedId = grpClosed.attr("id").replace("titl", "tbod") + "_";
grpClosed.insertAfter("#" + strGrpOpenId);
$("#" + strGrpClosedId).insertAfter(grpClosed);
}
});
So basically using this Code, I am changing the location of HTML code and putting them as per my need. So that it looks like custom sorting.
Hope this code will help other users.

Sorting a Google SpreadSheet or Google Doc table by column

I've made a script that takes data from a spreadsheet , creates a Google Doc and presents selected rows in a Table format in the Doc. Now I'd like to be able to sort that table Alphabetically before the table is created. I've tried using a couple of different approaches like this
function onEdit(){
var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var editedCell = sh.getActiveRange().getColumnIndex();
if(editedCell == 2) {
var range = sh.getRange("A2:B10");
range.sort({column: 2});
}
}
This kind of sort works but only onEdit(). I'd like to sort before edit or find away to sort the table as the Google Doc is being generated.
Does anyone have any suggestions.
Many thanks in advance.
Use the onOpen() function instead of the onEdit() function.
Note that you will have to open the document, not just refresh the page to get the function to run.

Populating dropdown list with two columns from database

I'm working on MVC3 project.
At my controller I already have a code that gets the Descr column from StockClass table. After that I fill a ViewBag with this list in order to retrieve it from the view and populate the dropdown list.
Currently is working fine but only shows Descr field (obviously). What i want is populate the dropdown list with two fields (Code and Descr) in this format: "code - descr".
I tried several ways but i cannot find the way to code the #Html helper correctly.
In my controller...
var oc = dba.StockClass.OrderBy(q => q.Code).ToList();
ViewBag.OrderClass = new SelectList(oc, "StockClassId", "Descr");
In my view....
#Html.DropDownList("StockClassID", (SelectList)ViewBag.OrderClass)
Could you please help me?
I don't believe there is an HTML Helper which will do that for you, but you can get what you're after like this:
var oc = dba.StockClass
.OrderBy(q => q.Code)
.ToDictionary(q => q.StockClassId, q => q.Code + " - " + q.Descr);
ViewBag.OrderClass = new SelectList(oc, "Key", "Value");
This also has the advantage of making the uses of StockClassId, Code and Descr refactor-friendly - if you rename those properties you won't be able to compile without updating this bit of code to match.

How to set default selected options in magento product detail page

I have requirement in which i am getting product ID from external Application with product super_attribute options like color,size. I am getting all those and i can do the add to cart option.
But here my actual requirement is to select the requested options by customer and redirect them to product detail page in magento so that here they can still enter optional text to print. So i need to set the requested options in detail page and redirect them to product detail page instead of adding it to cart. They will enter more details and then they will do addtocart manually.
How can i set the selected options while loading itself.
Please help me.
Thankfully this is already built in to most themes. You need to know the ID of both attributes and values from the Simple product that is included in the Configurable product. I've only seen it work with Configurable types so that might be a limitation.
For each attribute make a key=value pair
Combine the attributes as a query string, eg. "123=345&678=890"
Append the string as a hash fragment (not as a query).
This is an example from the official demo, note that the first option needs to be selected for the second to work so it has two key/value pairs.
http://demo.magentocommerce.com/zolof-the-rock-and-roll-destroyer-lol-cat-t-shirt-126.html#525=99&272=22
Rough Magento2 example add the below for pre-selecting the custom options by name=value in:
/www/mysite/app/design/frontend/mycompany/mytheme/Magento_Catalog/templates/product/view/options.phtml
The below code looks at the label of the option and the text value of the select. And depends on your theme structure. Example below for Luma.
It expects the following format in the url
product.html?SelectLabel=OptionValue&SelectLabel=OptionValue
This does not account for multi language etc.. you could easily adapt it to instead look for the select id and option id which would be more accurate replacing
$(label).parents().eq(1).find('select option:contains('+arr[k]+')').attr('selected', true);
with (untested)
$("#"+k+" option[id='"+arr[k]+"']").attr("selected", "selected");
<script>
require(['jquery'],function($){
$(document).ready(function(){
function getJsonFromUrl() {
var query = location.search.substr(1);
var result = {};
query.split("&").forEach(function(part) {
var item = part.split("=");
result[item[0]] = decodeURIComponent(item[1]);
});
return result;
}
var arr = getJsonFromUrl();
for (var k in arr){
if (arr.hasOwnProperty(k)) {
//alert("Key is " + k + ", value is" + arr[k]);
var label = $('.product-options-wrapper').find("span:contains('"+k+"')");
$(label).parents().eq(1).find('select option:contains('+arr[k]+')').attr('selected', true);
}
}
});
});
</script>

Resources