I am trying to create dynamic rows and cols based on the length of arryaOfString. I have a chart to display within the cols. So the JSON will have country list as Array of strings and based on the selection, I need to display individual country charts.
If arrayOfString's length == 1, 1 Row, 1 Col
If arrayOfString's length == 2, 1 Row, 2 Col
If arrayOfString's length == 3, 2 Row, 3 Col.
If arrayOfString's length == 4, 2 Row, 4 Col.
I've seen samples Creating div tag dynamically based on rows count where they are creating HTMLElements using JS but I am not sure If i can inject my Chart component using this logic.
Below is simple code sandbox, where I just hardcoded the values inside the Col. However I am unable to find or create any logic to achieve this task on dynamically adding new rows based on array length.. Please help.
https://codesandbox.io/s/bootstrap-grid-demo-on-react-using-reactstrap-forked-8xw0dy?file=/src/index.js
Related
I have a list of roughly 3,000 First Names, Last Names, and other items on a sheet in Google Sheets. The name of that sheet is "Database." (link below).
I want to create a script that takes 100 random entries from each column in "Database" and populates cells on another sheet called, "Results."
So, basically, Col 1 on "Results" would take 100 random results from Col 1 in "Database." Col 2 in "Results" would take 100 random results from Col 2 in "Database." So on and so forth. Ideally, this can be regenerated by assigning a script to a button on the sheet as opposed to using a formula that will create new results every time an action is performed.
Ultimately, I'll end up having about 10 columns or so, but I'm using test data for now just to get the structure built. Here's a link to the test document I'm using...
https://docs.google.com/spreadsheets/d/1qOgZxLtl8ruQHUDMkIjCNdXV3Jy5eOv0dC5DkLEpB8w/edit?usp=sharing
Thanks so much for the help!
You can try this:
Pre-requisite:
LodashGS Library should be added in your project
//Load LodashGS:
var _ = LodashGS.load();
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var resultSheet = ss.getSheetByName("Results");
var dBSheet = ss.getSheetByName("Database");
//Loop all columns in Database Sheet
for (var col = 1; col <= dBSheet.getLastColumn() ; col++){
//Generate an array of unique numbers from 2 to the last row number of the Database Sheet
const uniqRandomNumbers = _.sampleSize(_.range(2,dBSheet.getLastRow() + 1), 100);
Logger.log(uniqRandomNumbers);
var rowValues = [];
//Get the cell value based on the uniqRandomNumbers as row index, create a 2-d array of row values
uniqRandomNumbers.forEach(row=>{rowValues.push([dBSheet.getRange(row,col).getValue()]);});
//Write the row values into the Results Sheet with 100 row entries
resultSheet.getRange(2,col,100).setValues(rowValues);
Logger.log(rowValues);
}
}
What it does?
(This is done for each column)
Generate an array of unique numbers from the range provided in _.range(). We will use this unique array numbers as row indexes.
Get the cell value based on the unique array numbers generated in Step1, and create a 2-d array of row values.
Write the 2-d array of row values into the Results Sheet using .setValues()
Sample Output:
Additional References:
Creating array of length n with random numbers in JavaScript
I have 10 rows of data on my input step, i transform them in a for-loop and i should get more than 10 rows, but in this case i get the last transform of each iteration that the loop have for each data
I tried to use appendToFile() but the result data is not useful and pentaho read it as a unique header
On my alert() method i can see that the for loop transform the data.
var PERIODO = 2
var i
var fecha_final
//var ruta_acess ="D:\TEST.accdb"
//var contenido
////var contenido2
//var arreglo_completo
for (i=0; i<=PERIODO; i++){
fecha_final = dateAdd(FECHA_INICIO,"d",i)
Alert(i)
}
As I show in the below photo i get only 10 records and in the other photo appears the result that i want that are the results data of each iteration of the for-loop
Modified JavaScript value photo:
Expected result:
Obtained result:
For loops are not really a thing in PDI. Transformations work on sets of rows that flow through the steps, so it's best for performance and stability to use that mindset.
In your scenario each incoming row should end up as three copies, but with different calculated values based on a single new field (with values 0,1,2).
The way to do this in PDI is with a Join rows (cartesian product) step. It takes two sets of input rows and outputs a row for every combination of input rows, possibly filtered by defining a key field that has to match. So if you have 10 rows in the main input and 3 rows in the second, it will output 30 rows.
You will first need to create a data grid as the second input. Define a single integer field, name it something clear and on the second tab fill three rows with 0, 1 and 2 respectively.
Connect both inputs to the Join rows step. You don't need to configure any matching key.
The output of the Join step will be three rows for each input row, one with each of the values 0, 1, 2. Connect that output to a Calculator step and use the calculation Date A + B days to replace the logic from your javascript step.
what i mean is that in the obtained result photo the "i" variable only shows the value of "3" and i would like to have "1", "2" and "3"
to solve this i used
var row = createRowCopy(getOutputRowMeta().size())
var idx = getInputRowMeta().size()
row[idx++] = DPROCESS
this add a row for each result of the iteration.
before the tranformation result showed to me only the last value of each loop.
I have a column and I'd like to get the column following that particular column.
nhood,column,variablecolumn
Treasure Island,3,5
McLaren Park,1,2
Tenderloin,28,112
Lakeshore,14,8
Chinatown,15,103
I know the name of the second column, but in my dataset the name of the third column changes.
I tried variants on this idea. I'm trying to get the number "5" from the first row.
parseFloat(data[1]["column"+1]);
parseFloat(data[1]["column"]+1);
Another idea is to create an array with the column names, pull the index for "column" and then use index + 1 when I pull the data in that particular command.
Got it. Like mentioned, you can turn the column names into an array and then pull the index for a particular array. In this case, you can use col as a stand-in for the variablecolumn name.
var valueKey = data.columns;
var col = valueKey[valueKey.indexOf(dataset)+1];
I want to filter data on the basis of number of rows and columns provided by user.
I am getting the data on controller after reading this excel file:
this is the column header values which I am getting after user has passed 5 as input columns:
This is the row data which I am getting after user has given 4 rows as input to be rendered, here there is data of 4 rows:
Inside each row, there is key value pair containing column name and the cell value:
I want to filter this row data on the basis of the header names which are coming through column so that the row has only the values till the column is defined. Currently I am getting entire row values.
I have written a logic like this but this is not working.
var rowData=[];
for(var i=0;i<headerNames.length;i++){//headerNames contains column names
for(var j=0;j<data.length;j++){//data contains the rows data
for(var keyName in data[j])
if(angular.equals(keyName,headerNames[i])){
rowData.push({'keyName':data[j][keyName]})//I want only the key,values which matches the column names. I want to set the keyName value as array key but I am not getting its value instead it is coming like keyName:18
}
}
}
}
Adding the plunker for the code.
http://plnkr.co/edit/28Z44xDBug7nFCQnKZJL?p=preview
I am able to filter the data on UI and get only the row and column data as per user input.
But i need the same data on controller, so that i can save it in MongoDb. I want to filter the row data as per the column input. So, that i only get the row data till the column is defined.
Please suggest how can i filter the data and can splice the row values so that in row i can have value upto the column numbers defined. For eg, if I user have entered 4 rows and 5 columns then in my row Data i can have only values upto 5th column and all other values i can remove from array. in my code currently i am not able to get the key value to be set as array key.
Please help me to resolve this problem.
Looks like you're most of the way there. You just need to assign rowData to be $scope.rowData so that angular can get to it, and have the Angular document show {{rowdata}} (shows $scope.rowData).
You'll probably need to arrange it into columns though so you might do a ng-repeat on rowData, with variable=row, and in TR TD tags show row.1
eg something like ..
<tr ng-repeat="row in rowData">
<td>{{row.1}}</td>
<td>{{row.2}}</td>
</tr>
I had interview and question asked was:
Write a JS plugin that can take cell and value as input and render excel format output on browser. For example,
Given Input (cell and value):
J3 = 5
A2 = 20
K1 = 10
Output on browser should be in excel format
A B C ....... J K .......
1 10
2 20
3 5
..
I Was looking for correct solution for the problem.
I tried solving this problem (writing psudeo code)
var cell = {"J3": 5, "A2":20, "K1": 10}
// Function they will call for generate excel style table
generateExcel(cell, selector) {
1. create blank table which has A-Z column (with selector as A-Z resp) and 1 to 100 rows (with selector as 1 to 100 resp)
2. Loop through each cell and for each cell
2.1 find the column (J) and row (3)
2.2 Add/replace value in that TD
3. Once all the information from cell in enter in table, print the table in the document at given selector
}
They said it won't be efficient for huge number of cell inputs. I suggest that we can use Matrix create table
A B... J K ....
1 [ 10 ]
2 20
3 5
I think you started off well. Begin by creating a table that will contain the elements. This will be 26 columns wide and as tall as the largest y value. Convert the letters to numbers.
Sorry for w3schools link, I'm liable to get downvoted for even mentioning them, but they have the best laid out documentation on the table object that I could google for you. I will update it if someone has something better.
http://www.w3schools.com/jsref/dom_obj_table.asp
MDN Tutorial
https://developer.mozilla.org/en/Traversing_an_HTML_table_with_JavaScript_and_DOM_Interfaces
You can then access the table cell most efficiently through
var table = ;//get by id or create element, not sure what they expect
table.rows[y].cells[x].appendChild(...);
Excel spreadsheets are tables. Can you use a simple table? If so, I would recommend the CSS border-collapse property to make it look better, as well as perhaps reducing cell padding and margin.