How to dynmically make a cell editable in jqGrid PHP - jqgrid-php

I have a jqGrid PHP project where I have been able with the below code to make rows background color and editable = false, based on the value of a cell in that row.
$rowattr = <<<ROWATTR
function (rd) {
if (rd.br_re_ending == "OTFN") {
return { "style": "background-color:#FF9999; background-image:none;", "editable": false };
}
}
ROWATTR;
$grid->setGridEvent('rowattr', $rowattr);
What I am now trying to do is to similarly use the value of a cell to determine if another cell in that same row should be editable or not. I have tried several options like the below, but with no avail.
$rowattr = <<<ROWATTR
function (rd) {
if (rd.br_ch_flag_extrameals == "STD") {
return { "setColProp", "br_ch_ch2_mon", "editable": True };
}
}
ROWATTR;
$grid->setGridEvent('rowattr', $rowattr);
Can someone please provide some help or guidance in how to achieve this?
Thanks,
Adri

Related

Tabulator - How to set value inside cellEdited function

I am using the Tabulator plugin and am using the editorParams function to select from a list of options. If a value isn't selected (eg: Cancelled) I want it to revert to the old (previous) cell value and do nothing, but calling cell.setValue() keeps retriggering the cellEdit function and it gets stuck in a loop.
table.on('cellEdited', function(cell) {
var cellOldValue = cell.getOldValue();
var cellNewValue = cell.getValue();
var row = cell.getRow();
var index = row.getIndex();
if (cellNewValue == 'none-selected') {
cell.setValue(cellOldValue);
} else {
if (confirm('Are you sure?')) {
// ok, do something
} else {
cell.setValue(cellOldValue);
}
}
});
This just keeps triggering the prompt. Any solutions, thank you?

Hide a row from rendering without filtering?

I would like to do something like Grouping with a bottomRowCalc but having the visibility of the rows of data being optional. Currently I'm using getData('active') to add up the values and row.update() on the "sum" row with the values. But if I filter out the data rows, they wont appear in the getData('active'), so I'd have do a getData().forEach(row => {}) and manually check for another field flag I guess to see if it should be included in the sum.
It sure would be nice if I could continue to use getData('active') but set row.visibility(false) on rows I dont want to show, but still be in active ?
Is answering your own question a sin ?
Anyway, for posterity, in case anyone else wants to do this :
rowFormatter:function(row) {
let display = 'inline-block';
if (some_condition) display= 'none';
row.getElement().style.display = display;
return true;
}
rowFormatter: function(row){
var row_data= row.getData()
console.log('row_data is...',row_data);
if (row_data === 'yes'){
const children = row.getElement().childNodes;
children.forEach((child) => {
child.style.backgroundColor = 'red';
})
}
else (row_data === 'Upcomming')
{ let display = 'inline-block';
display= 'none';
row.getElement().style.display = display;
return true;
}
},
In this case you will miss s.r. with the row

Problem with cell style in pivot mode Ag-grid

I have a problem with cell style in pivot mode: all mode such as row group and simple grid work well, but when I change to pivot mode just row style works and the cell style is not working.
See the link below
https://plnkr.co/edit/8AFyzB5XvqlQg51Q
I use this code in colDef
cellStyle: {color: 'red', 'background-color': 'green'}
and getRowStyle in gridOptions
var gridOptions = {
getRowStyle : function(params) {
if (params.node.rowIndex % 2 === 0) {
return { background: 'blue' };
}
}
}
Please guide me.
well coldef in AG-grid refers a simple column but the moment you perform grouping and pivoting its no longer a simple column it becomes a groupcolumn and if its autogroupcolomn then ag grid generates it. so if you want to apply styles to row group in grouped or pivot mode then you have to define it like this.
autoGroupColumnDef: {
width: 180,
cellStyle: function(params) {
//check that the autogroup is built using country column and then color every odd cell
if(params.node.field ==='country' && params.node.rowIndex% 2 === 1){
return {color: 'red', 'background-color': 'white'}
}
}
},
check out this fiddle to see the working demo

How to group rows or columns in Excel using Office JS API

I am converting a VSTO Excel add-in to a Web Excel add-in (using JavaScript API for Office). In my VSTO C# code I have the following line:
worksheet.Rows[rowStart + ":" + rowEnd].Group()
and a similar line for columns:
worksheet.Columns[colStart + ":" + colEnd].Group();
What is the equivalent API call for Office-JS? Could not find a relevant entry in the API Docs
I'm afraid that that kind of grouping is not yet supported in office.js. Please vote up the suggestion in the Office Developer Suggestion box: Grouping and ungrouping rows and columns.
See --> https://learn.microsoft.com/en-us/office/dev/add-ins/excel/excel-add-ins-ranges-group
https://learn.microsoft.com/en-us/javascript/api/excel/excel.range?view=excel-js-preview#excel-excel-range-group-member(1)
Here is how I did it. First thing I noticed was that I wanted certain groups to be collapsed by default. I accomplished this w/ hidden = true which combined w/ grouping, its more of a hide by default.
const Rng_Group_Obj = {
"group": {
"groupOptionString": {
"ByRows": "ByRows",
"ByColumns": "ByColumns",
},
},
"columnHidden": true,
"rowHidden": true,
}
function Do_Group_Rng(rng, ByColumns, ByRows, Opt_Hidden_By_Default) {
if (ByColumns == true) {
rng.group(Rng_Group_Obj.group.groupOptionString.ByColumns)
if (Opt_Hidden_By_Default == true) { rng.columnHidden = Rng_Group_Obj.columnHidden }
}
if (ByRows == true) {
rng.group(Rng_Group_Obj.group.groupOptionString.ByRows)
if (Opt_Hidden_By_Default == true) { rng.rowHidden = Rng_Group_Obj.rowHidden }
}
return true;
}
var ws = context.workbook.worksheets.getActiveWorksheet()
var rng = ws.getRange("G:K")
Do_Group_Rng(rng,true,false,true)
var rng = ws.getRange("4:7")
Do_Group_Rng(rng, false, true, true)

protractor: filter until finding first valid element

I am doing e2e testing on a site that contains a table which I need to iterate "until" finding one that doesn't fail when I click on it.
I tried it using filter and it is working:
this.selectValidRow = function () {
return Rows.filter(function (row, idx) {
row.click();
showRowPage.click();
return errorMessage.isDisplayed().then(function (displayed) {
if (!displayed) {
rowsPage.click(); // go back to rows Page, all the rows
return true;
}
});
}).first().click();
};
The problem here is that it is iterating all available rows, and I only need the first one that is valid (that doesn't show an errorMessage).
The problem with my current approach is that it is taking too long, as my current table could contain hundreds of rows.
Is it possible to filter (or a different method) and stop iterating when first valid occurrence appears?, or could someone come up with a better approach?
If you prefer a non-protractor approach of handling this situation, I would suggest async.whilst. async is a very popular module and its highly likely that your application is using it. I wrote below code here in the editor, but it should work, you can customize it based on your needs. Hopefully you get an idea of what I'm doing here.
var found = false, count = 0;
async.whilst(function iterator() {
return !found && count < Rows.length;
}, function search(callback) {
Rows[count].click();
showRowPage.click();
errorMessage.isDisplayed().then(function (displayed) {
if (!displayed) {
rowsPage.click(); // go back to rows Page, all the rows
found = true; //break the loop
callback(null, Rows[count]); //all good, lets get out of here
} else {
count = count + 1;
callback(null); //continue looking
}
});
}, function aboutToExit(err, rowIwant) {
if(err) {
//if search sent an error here;
}
if(!found) {
//row was not found;
}
//otherwise as you were doing
rowIwant.click();
});
You are right, filter() and other built-in Protractor "functional programming" methods would not solve the "stop iterating when first valid occurrence appears" case. You need the "take some elements while some condition evaluates to true" (like the itertools.takewhile() in Python world).
Fortunately, you can extend ElementArrayFinder (preferably in onPrepare()) and add the takewhile() method:
Take elements while a condition evaluates to true (extending ElementArrayFinder)
Note that I've proposed it to be built-in, but the feature request is still open:
Add takewhile() method to ElementArrayFinder

Resources