Is there any way to get a hover tool tip working on a shiny data table that has some information, this is possible on graphs but never seen it done before on a data table
Yes, like this (no need of Shiny):
library(DT)
datatable(head(iris),
options=list(initComplete = JS(c(
"function(settings){",
" var table = settings.oInstance.api();",
" var cell = table.cell(2,2);",
" cell.node().setAttribute('title', 'TOOLTIP CONTENTS');",
"}")))
)
table.cell(2,2) means the cell at row 2 and column 2; indices start at 0 in Javascript, and the column of row names is taken into account.
Related
Using DocX I need to do something like this:
A long
text description.
Except I need the "1." to be a paragraph and the "A long text description" to be a paragraph. I cannot use a list for this.
late answer, but use a 2 column table with no visible borders
some code i hacked out of my current thing. this makes a table and populates the cells with the contents of my cells,
you'd just need to make a table, with 2 columns. and then iterate build a row with with cell[0] for the numeral, and cell[1] for the sentence
doc.InsertParagraph("Table Title: " + (component).SubTitle, false, SubtitleStyle);
var table = doc.AddTable(component.ColumnCount, component.RowCount);
int rowcount = 0;
foreach (DataCell datacell in component.TableData)
{
table.Rows[rowcount].Cells[0].Paragraphs.First().Append(rowcount+1);
table.Rows[rowcount].Cells[1].Paragraphs.First().Append(datacell.CellValue);
rowcount++;
}
doc.InsertTable(table);
I've been searching for similar solutions out there but am coming up short so far. Here is what I want to accomplish:
I need to come up with a basic solution to sync inventory quantities at the end of each day. We take physical counts of inventory sold throughout the day but need something to log these changes and share between users. I would like to utilize two buttons (click one to subtract amount of items sold at the end of the day and click one button to add newly received inventory).
This is how my sheet is set up:
Col A: Product Tag
Col B: Product sku
Col C: Amount Sold Today
Col D: Total Inventory Quantity
Col E: Add New Inventory
Column D will be pre-populated with initial inventory counts. At the end of each day, I would like to go down my product list and fill in the amount of each item sold that day in Column C. Once Column C is fully populated, I would like to click the "subtract" button and have Column C subtracted from Column D.
On the other side, once we receive new stock of an item I would like to enter these counts into Column E. Once this column is fully populated, I would like to click the "Add" button and have Column E added to Column D. Ideally once the add or subtract function has been completed, columns C or E will be cleared and ready for the next days entry.
I already have designed my buttons, I just need help coming up with the scripts to accomplish this.
You can use Google Apps Script for this.
If you are unfamiliar, in your particular spreadsheet, go to Tools → Script Editor and then select the Blank Project option.
Then you can write functions like this to achieve what you want!
function subtractSold() {
var sheet = SpreadsheetApp.getActiveSheet();
var c1 = sheet.getRange("C2");
var c2 = sheet.getRange("D2");
while (!c1.isBlank() && !c2.isBlank()){
c2.setValue(c2.getValue() - c1.getValue());
c1.clear();
c1 = c1.offset(1, 0);
c2 = c2.offset(1, 0);
}
}
Basically what the function does is:
Get a reference to the active spreadsheet
Get references to the cells C2 and D2, for the first row of data.
Use a while loop to repeated go through the rows. Terminate when either cell is empty.
In the loop, we get the appropriate values, subtract and set the value back into the cell. Then we clear the cell in column C. We then move both cell references down by one row (the offset method returns a reference to the original cell, but offset by row, column).
Then assign the script to the button image by entering the name of the function (subtractSold in this case) in the "Assign script" option for the button.
I have made an example sheet here (go to File → Make a Copy to try the scripts and see the code): https://docs.google.com/spreadsheets/d/1qIJdTvG0d7ttWAUEov23HY5aLhq5wgv9Tdzk531yhfU/edit?usp=sharing
A bit faster
If you try the sheet above you can see it processes one row at a time, which might get pretty slow when you have a lot of rows. It is probably faster to process the entire column in bulk, but it may be a bit more complicated to understand:
function subtractSoldBulk() {
var sheet = SpreadsheetApp.getActiveSheet();
var maxRows = sheet.getMaxRows();
var soldRange = sheet.getRange(2, 3, maxRows); // row, column, number of rows
var totalRange = sheet.getRange(2, 4, maxRows);
var soldValues = soldRange.getValues();
var totalValues = totalRange.getValues();
for (var row in soldValues) {
var soldCellData = soldValues[row][0];
var totalCellData = totalValues[row][0];
if (soldCellData != "" && totalCellData != "") {
totalValues[row][0] = totalCellData - soldCellData;
soldValues[row][0] = "";
}
}
soldRange.setValues(soldValues);
totalRange.setValues(totalValues);
}
The difference here is that instead of getting one cell, we get one range of cells. The getValues() method then gives us a 2D array of the data in that range. We do the calculations on the two arrays, update the data in the arrays, and then set the values of the ranges based on the array data.
You can find documentation for the methods used above from Google's documentation: https://developers.google.com/apps-script/reference/spreadsheet/sheet
I have read this article and tested, it works but my problem is that there are one wide empty column (column A) and one wide empty row (row 1) in every sheet (in excel file). I know that this is the setting of PrintingBase class. But how can i remove those first empty column and row ?
i have found the answer to my own question:
var compositeLink = new CompositeLinkBase();
var link1 = new PrintableComponentLinkBase();
// this is the margins in sheet1
link1.Margins.Left = 0;
link1.MinMargins.Left = 0;
link1.Component = DG1;
compositeLink.Links.Add(link1);
// then export to excel :)
I have a List with following values
List<Calculations> calcs = new List<Calculations>();
Calculations cal = new Calculations();
cal.TotalTotalC2 = Convert.ToInt32(reader["TotalTotalC2"].ToString());
cal.TotalTotalC3 = Convert.ToInt32(reader["TotalTotalC3"].ToString());
cal.TotalC1C4IOM = Convert.ToInt32(reader["TotalC1C4IOM"].ToString());
cal.TotalC1C4MDR = Convert.ToInt32(reader["TotalC1C4MDR"].ToString());
calcs.Add(cal);
i need to Bind these Numeric values in the following table format.left hand side plain text and right hand side the bound values.
Can some one plz tell me that how can i use GridView to bind in above format.
you have to write code in RowDataBound event , and check for row number in each iteration and based on the row number bind the column text of your custom list to the column, I don't think there is any auto function to bind column names to grid!!! let me know if you find something direct and easy
I had to dynamically generate a DataTable and then bind it to GridView
DataTable dt=new DataTable();
dt.Columns.Add("Title", typeof(string));
dt.Columns.Add("Count", typeof(int));
foreach (Calculations item in calcs )
{
dt.Rows.Add("Total ...", item.TotalTotalC2);
dt.Rows.Add("Total ...", item.TotalTotalC3);
}
I've got a GridView in ASP.NET 2.0 with AutoGenerateColumns set to true. It'll be bound at runtime to a DataSet with one of many possible schemas, and I'd rather not set up grids and columns for each possible schema.
Some of the columns in the grid will sometimes be floating point values. It seems the default number formatting turns 0.345 into 0.345000. Is there a way to change the default number format so it trims to a set number of decimals?
You could use strings in your schema instead of floating point for display purposes, and perform the formatting manually, something like this:
EDIT: Without LINQ, you can do the same thing by modifying rows in the schema:
// load source data
DataSet myData = GetDataSet();
// create column for formatted data.
myData.Tables["MyTable"].Columns.Add("AmountFormatted", typeof(string));
// apply formatting
foreach (DataRow dr in myData.Tables["MyTable"].Rows)
dr["AmountFormatted"] = string.Format("{0:0.###}", dr["Amount"]);
// remove source column and replace with formatted column
myData.Tables["MyTable"].Columns.Remove("Amount");
myData.Tables["MyTable"].Columns["AmountFormatted"].ColumnName = "Amount";
C#, LINQ-Based solution:
var theData = GetDataSchema1();
var dataSource = theData.Tables["MyTable"].Select().Select(dr =>
new { /* select only columns you want displayed, and apply formatting */
MyColumn1 = dr["MyColumn1"],
MyColumn2 = dr["MyColumn2"],
MyColumn3 = String.format("#.###", dr["MyColumn3"]),
MyColumn4 = dr["MyColumn4"],
MyColumn5 = dr["MyColumn5"]
}
);
MyGridView1.DataSource = dataSource;
MyGridView1.DataBind()