Is there any method to get the column number from the column name?
I can only retrieve the column name, and I need the column number for getCellMeta.
Thanks
Made this function that solved my problem:
function GetColFromName(name)
{
var n_cols = $editorTableContainer.handsontable('countCols');
var i = 1;
for (i=1; i<=n_cols; i++)
{
if (name.toLowerCase() == $editorTableContainer.handsontable('getColHeader', i).toLowerCase()) {
return i;
}
}
return -1; //return -1 if nothing can be found
}
This is almost what I required but not quite as I needed the column prop. I couldn't find the answer anywhere so thought I would add this to the thread that helped me.
instead of using 'getColHeader' use 'colToProp'.
Use propToCol("Column Name"). This returns the column's index.
Related
I am not able to fetch a max value from a number field in AppMaker. The field is filled with unique integers from 1 and up. In SQL I would have asked like this:
SET #tKey = (SELECT MAX(ID) FROM GiftCard);
In AppMaker I have done the following (with a bit help from other contributors in this forum) until now, and it returns tKey = "NaN":
var tKey = google.script.run.MaxID();
function MaxID() {
var ID_START_FROM = 11000;
var lock = LockService.getScriptLock();
lock.waitLock(3000);
var query = app.models.GiftCard.newQuery();
query.sorting.ID._descending();
query.limit = 1;
var records = query.run();
var next_id = records.length > 0 ? records[0].ID : ID_START_FROM;
lock.releaseLock();
return next_id;
}
There is also a maxValue() function in AppMaker. However, it seems not to work in that way I use it. If maxvalue() is better to use, please show :-)
It seems that you are looking in direction of auto incremented fields. The right way to achieve it would be using Cloud SQL database. MySQL will give you more flexibility with configuring your ids:
ALTER TABLE GiftCard AUTO_INCREMENT = 11000;
In case you strongly want to stick to Drive Tables you can try to fix your script as follow:
google.script.run
.withSuccessHandler(function(maxId) {
var tKey = maxId;
})
.withFailureHandler(function(error) {
// TODO: handle error
})
.MaxID();
As a side note I would also recommend to set your ID in onBeforeCreate model event as an extra security layer instead of passing it to client and reading back since it can be modified by malicious user.
You can try using Math.max(). Take into consideration the example below:
function getMax() {
var query = app.models.GiftCard.newQuery();
var allRecords = query.run();
allIds = [];
for( var i=0; i<allRecords.length;i++){
allIds.push(allRecords[i].ID);
}
var maxId = Math.max.apply(null, allIds);
return maxId;
}
Hope it helps!
Thank you for examples! The Math.max returned an undefined value. Since this simple case is a "big" issue, I will solve this in another way. This value is meant as a starting value for a sequence only. An SQL base is better yes!
Please take a look at the following googleapps script code. the spreadsheet it references has 4 values in it. in a2 is the value "Two". I want that when I run this code, i receive an email with "2" in the subject line. I seem to keep on receiving a "4". Any ideas?
function rowofspecificvalue(){
var sheet = SpreadsheetApp.openById("1rMUrZFie94RLFDKaWVBPsQ-jebL8wNA6qsZWivMBDTk").getActiveSheet();
var data = sheet.getRange("a1:a4").getValues();
for(var i = 0; i<data.length;i++){
if(data[i][1] == "Two"){
Logger.log((i+1))
return i+1;
}
} MailApp.sendEmail ("fake_email#gmail.com", i, "");
}
Thanks!
Write
MailApp.sendEmail("fake_email#gmail.com", i-2, "")
and you will "2" have in subject. Second argument of MailApp.sendEmail() function set up subject of email.
I think I've not found this answer on stackoverflow. I've need codeigniter function that will return me 0 if table is empty and max int from table if there is some data.
songs(IDSon, title)
I've tried with:
$this->db->select_max('IDSon');
$query = $this->db->get('songs');
But how can I access "IDSon" field, and to add IF clause if table is empty to get 0?
Thanks
function get_max_number() {
$result = $this->db->select_max('IDSon')->get('songs')->result_array();
return (int) $result[0]['IDSon'];
}
rowname="r1";
changes[1]["num1"] = "changed";
grid.invalidateRow(1);
grid.setCellCssStyles("highlight", changes);
grid.render();
Is there a way to get the index of a row in slickgrid if I have a cell value of first column which is unique? In the above code I want to use as changes[rowindex]["num1"]="changed" where "num1" is my column name and "r1" is first column cell value.changes["r1"]["num1"]="changed" does not works.
Do it like this...
for(var i=0; i<grid.getDataLength(); i++){
if(grid.getData()[i].firstColumnID == 'firstColumnValue'){
rowIndex = i;
}
}
getRowById(id) - Returns the index of a row with a given id
I know I'm late but may be with better solution?
grid.getData().getIdxById('UniqueFieldValue')
I've got a list of IQueryable. I'm trying to split this list into an array of IQueryable matching on a certain field (say fieldnum) in the first list...
for example, if fieldnum == 1, it should go into array[1]. I'm using Where() to filter based on this field, it looks something like this:
var allItems = FillListofMyObjects();
var Filtered = new List<IQueryable<myObject>(MAX+1);
for (var i = 1; i <= MAX; i++)
{
var sublist = allItems.Where(e => e.fieldnum == i);
if (sublist.Count() == 0) continue;
Filtered[i] = sublist;
}
however, I'm getting the error Field "t1.fieldnum" is not a reference field on the if line. stepping through the debugger shows the error actually occurs on the line before (the Where() method) but either way, I don't know what I'm doing wrong.
I'm farily new to LINQ so if I'm doing this all wrong please let me know, thanks!
Why don't you just use ToLookup?
var allItemsPerFieldNum = allItems.ToLookup(e => e.fieldnum);
Do you need to reevaluate the expression every time you get the values?
Why not use a dictionary?
var dictionary = allItems.ToDictionar(y => y.fieldnum);