Unable to hide handsontable column header when i use td.hidden = true; cell render - handsontable

I have used the following custom column render code for hiding handsontable column
function getCustomRenderer() {
return function(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
if (colsToHide.indexOf(col) > -1) {
td.hidden = true;
} else {
td.hidden = false;
}
}
but when i set colHeaders: true, the column headers does not get hidden.
http://jsfiddle.net/LkLkd405/91/

Correct, you can't hide the column headers that way since the rendering happens independently of the column renderers. I will go ahead and assume your endgoal is to put in data into your data object that you would like to hide, like a database ID. The solution is to use the columns definition.
This option, if you read the documentation carefully, allows you to define which columns to show. So, for example, if you had 3 columns plus your ID column, you would have:
var colHeaders = ['col1', 'col2', 'col3', 'ID'];
// assume `dataArray` is an aray you previously defined, with row Objects with 4 keys each, corresponding to the first 3 real data columns and the fourth as the ID.
columns: [{
data: colHeaders[0],
type: 'text'
},{
data: colHeaders[1],
type: 'text'
},{
data: colHeaders[2],
type: 'text'
}]
Now you don't even need to have a custom renderer as the table will omit that fourth value.

hot.addHook('afterGetColHeader', RemoveUnWantedHeader);
function RemoveUnWantedHeader(col, th) {
if (th.textContent == "A" || th.textContent == "B" || th.textContent == "C"
|| th.textContent == "D" || th.textContent == "E"
|| th.textContent == "F" || th.textContent == "G" || th.textContent == "H"
|| th.textContent == "I" || th.textContent == "J"
|| th.textContent == "K" || th.textContent == "L" || th.textContent == "M"
|| th.textContent == "N" || th.textContent == "O"
|| th.textContent == "P" || th.textContent == "Q" || th.textContent == "R"
|| th.textContent == "S" || th.textContent == "T"
|| th.textContent == "U" || th.textContent == "V" || th.textContent == "W"
|| th.textContent == "X" || th.textContent == "Y" || th.textContent == "Z"
|| th.textContent == "AQ" || th.textContent == "AR" || th.textContent == "AS"
|| th.textContent == "AT" || th.textContent == "AU" || th.textContent == "AV" || th.textContent == "AW") {
th.style.display = 'none';
}
}
I have used hook to remove the headers I need to. I tried the same inside my HandsonTable it doesn't work so I tried the same using addHook and worked like charm.
afterGetColHeader: It is a function which will be rendered when header is called.
RemoveUnWantedHeader: It is my own callback. You can have your own conditions and can remove.
Reference: Handsontable Add Hooks

Related

Ignore part of the linq query if variable equals a specific value

var longlinq = viewModel.Where(x => (x.Systems.Storage == SelectOption || x.Systems.Laptop == SelectOption ||
x.Systems._2In1 == SelectOption ||
x.Systems.Convertible == SelectOption )
||
(x.Component.Components == SelectOptionComp ||
x.Component.Boards == SelectOptionComp)
||
( x.Service.Services == SelectOptionSer ||
x.Service.DevelopmentTools_andServices == SelectOptionSer )
||
(x.Software.Softwares == SelectOptionSoft ||
x.Software.Analytics == SelectOptionSoft)
||
(x.Application.Applications == SelectOptionApp ||
x.Application.PrintImaging_andOfficeAutomation ));
Let me explain my question with an example:
For instance SelectOptionComp equals "-", then I want to ignore the parts where I used
SelectOptionComp in longlinq or set SelectOptionComp to " " in the longlinq.
I don't want to use ifs because of large number of combinations.
How do I do that?
I have used ternary operator Use the ternary operator: (SelectOptionComp == "-" ? true : (x.Component.Components == SelectOptionComp || x.Component.Boards == SelectOptionComp))

How to simplify a simple loop in Javascript?

I am now trying it out for a while and get it perfect. I am trying to simplify this for loop I created and make it actually work, without any arrays and only the most basic of basic JavaScript.
for (var x=0;x<=1;x++) {
if (secondInput == luckyNumber || secondInput == luckyNumber2 || secondInput == luckyNumber3) {
if (thirdInput == luckyNumber || thirdInput == luckyNumber2 || thirdInput == luckyNumber3) {
if (firstInput == luckyNumber || firstInput == luckyNumber2 || firstInput == luckyNumber3) {
while (firstInput !== secondInput){
while(firstInput !== thirdInput){while(secondInput !== thirdInput) {
alert('Congratulations! You got all 3 numbers correct. You\'ve won £1,000!');
}
}
}
}
}
}
Does this code make sense or am I doing something wrong? I've got the feeling that I can even leave the loop out, but it is the only way how I think it is correct.
Write a function that takes the input, compares it to the lucky numbers and returns a boolean with the result.
Call that function in your if clauses.
I don't quite understand what you are trying to do with the while loops.
You could try using this idea to help:
[1, 3, 2].sort()
(store your questions and answers in arrays, and sort both then compare. Of course, checking javascript arrays for equality is a fun new project :) )
Here you go. You said you wanted it simplified.
for (var x = 0; 1 >= x; x++) {
if (!(secondInput != luckyNumber && secondInput != luckyNumber2 && secondInput != luckyNumber3 || thirdInput != luckyNumber && thirdInput != luckyNumber2 && thirdInput != luckyNumber3 || firstInput != luckyNumber && firstInput != luckyNumber2 && firstInput != luckyNumber3)) {
while (firstInput !== secondInput) {
while (firstInput !== thirdInput) {
while (secondInput !== thirdInput) {
alert("Congratulations! You got all 3 numbers correct. You\'ve won £1,000!");
}
}
}
}
}

Linq to nHibernate - exclude elements without child elements

var locations = (from location in session.Query<Location>()
where
(location.MB_ID == 0 || location.MB_ID == null) &&
(location.hide != "Y" || location.hide == null) &&
(location.locationNameRaw != "" && location.locationNameRaw != null) &&
((location.isIPCapableText != "" && location.isIPCapableText != null) || (
(location.ISDNNumber1 != null && location.ISDNNumber1 != "") ||
(location.ISDNNumber2 != null && location.ISDNNumber2 != "") ||
(location.ISDNNumber3 != null && location.ISDNNumber3 != "") ||
(location.ISDNNumber4 != null && location.ISDNNumber4 != "") ||
(location.ISDNNumber5 != null && location.ISDNNumber5 != "") ||
(location.ISDNNumber6 != null && location.ISDNNumber6 != "")
))
&& (location.privateRoom == "N" || location.privateRoom == "" || location.privateRoom != null)
&& (
from lll in session.Query<LocationLonLat>()
where
location.locationID == lll.locationId
select lll.locationId
).Any()
&& (location.LastUpdatedTime > lastUpdateTime)
&& location.LocationTimes.Count() > 0
/*&& (
from lt in session.Query<LocationTimes>()
where
location.locationID == lt.LID
select lt.LID
).Any()*/
select location
)
.ToList();
There is a relationship between Location (1) and LocationTimes (many), and I only want to return a dataset of locations that have at least one LocationTime record.
I tried a couple of things...
When I add the line:
&& location.LocationTimes.Count() > 0
or if I add the line:
&& (
from lt in session.Query<LocationTimes>()
where
location.locationID == lt.LID
select lt.LID
).Any()
The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
I suspect that this may because of the size of the dataset or something...
Is there a better way of doing this? Like with a 'left outer join' or something?
I think a simple join should do it.
from locationTime in Query<LocationTime>()
join location in Query<Location>() on locationTime.Location.LocationId equals location.LocationId
join locationLat in Query<LocationLat>() on location.LocationLat.LocationLatId equals locationLat.LocationLatId
where ...
select location;

Linq query with multiple conditions

how to write the linq query with these conditions..first we have to check the OrderType if this is true then and condition should be checked.How to write the query..if i close the condition at .OrderType.XYZ) then it says 'zj' doesn't belong to the current context..if we remove that no error but we r not getting the req result
bool btnvisible= datacontext.GetOrders(new List<Items> { selectedItem }).
.Where((zj => wo.OrderId== (int)BL.OrderType.PQR || zj.OrderId== (int)BL.OrderType.XYZ)
&&( zj.OrderId== (int)BL.Statuses.Assigned
|| zj.OrderId== (int)BL.Statuses.Planned
|| zj.OrderId== (int)BL.Statuses.InProgess
|| zj.OrderId== (int)BL.Statuses.Paused
|| zj.OrderId== (int)BL.Statuses.Ready)).Any();
return btnEnable;
I think this is due to some misplaced brackets. You have .Where((zj => ...) ... zj ...). The variable zj doesn't exist outside of the first set of brackets. It should be something like:
bool btnvisible= datacontext.GetOrders(new List<Items> { selectedItem })
.Where(zj => (wo.OrderId== (int)BL.OrderType.PQR || zj.OrderId== (int)BL.OrderType.XYZ)
&& (zj.OrderId== (int)BL.Statuses.Assigned
|| zj.OrderId== (int)BL.Statuses.Planned
|| zj.OrderId== (int)BL.Statuses.InProgess
|| zj.OrderId== (int)BL.Statuses.Paused
|| zj.OrderId== (int)BL.Statuses.Ready)).Any();
return btnEnable;
You appear to have a mismatched parenthesis problem.
.Where((zj => wo.OrderId== (int)BL.OrderType.PQR || zj.OrderId== (int)BL.OrderType.XYZ)
^ ^
That's mucking with the scope of your variable. Revisit it.
var readyStats = new [] {
(int)BL.Statuses.Assigned,
(int)BL.Statuses.Planned,
(int)BL.Statuses.InProgess,
(int)BL.Statuses.Paused,
(int)BL.Statuses.Ready,
};
var orderTypes = new [] {
(int)BL.OrderType.PQR,
(int)BL.OrderType.XYZ
}
bool btnvisible= datacontext.GetOrders(new List<Items> { selectedItem }).
.Where(wo => orderTypes.Contains(wo.OrderId) && readyStats.Contains(wo.OrderId)).Any();
or
bool btnvisible= datacontext.GetOrders(new List<Items> { selectedItem }).
.Any(wo => orderTypes.Contains(wo.OrderId) && readyStats.Contains(wo.OrderId));
I think the problem is here:
.Where((zj => wo.
The right version should be:
.Where(zj => zj.

Silly question about how you format long if statements

On long if statements where they take up more than one line, do you put the conditions like AND or OR on a new line like this:
if (something
&& something else)
Or like this:
if (something &&
something else)
For complex conditions, consider extracting it into a function or a variable:
if (complexCondition(foo)) { ..
As a bonus, the name of the function or variable can be used to communicate what the condition means. This makes your code easier to read.
I typically do it the second way, since I can line up the statements. However, either way is fine when you're writing code, as long as you're consistent.
I prefer a rendition of the first. My reasoning is that deleting a condition via cut/paste/comment for any testing purposes is easier. It's a lot easier to comment out a line than it is to delete the and from the line above and comment out a line. This is more when I'm doing where clauses in SQL than in an if statement in any other given language, but is similar.
Given my druthers, I'd avoid long if tests in the first place. I'd rather do something like:
bool fTest1 = A == B ;
bool fTest2 = C ;
bool fTest3 = f(1,2,3) ;
bool fSuccess = ( fTest1 | ftest2 ) & fTest3 ;
if ( fSuccess )
...
Otherwise something like this:
if ( A == B
&& ( C == D
|| E == F
)
&& Z > Y
) {
...
}
else
{
...
}
YMMV, of course.
The former is far easier to debug, test, log, etc.
I usually format using the IDE formatter and then rearrange a bit to make it look beautiful.
I'm working in VSC and recently managed to not only write, but make readable very long conditions in nested if statements. Just use brackets and new lines like this. It should make automatic indentations:
foreach ($panstwa as $key => $value) {
if (is_object($value)) {
if (
(
($value->checkbox1 === true) && (is_string($value->panstwoZListy)) && ($value->panstwoZListy !== 'none') && ($value->panstwo === '') && ($value->panstwoZListy !== '')
) ||
(
(
($value->checkbox2 === true &&
($value->checkbox2_1 === true || $value->checkbox2_2 === true || $value->checkbox2_3 === true || $value->checkbox2_4 === true || $value->checkbox2_5 === true || $value->checkbox2_6 === true)
) ||
($value->checkbox3 === true &&
($value->checkbox3_1 === true || $value->checkbox3_2 === true)
) ||
($value->checkbox4 === true &&
(
(
($value->checkbox4_1 === true || $value->checkbox4_2 === true || $value->checkbox4_3 === true || $value->checkbox4_4 === true || $value->checkbox4_5 === true || $value->checkbox4_6 === true || $value->checkbox4_7 === true) && ($value->checkbox4_8 === false)
) ||
(
($value->checkbox4_1 === false && $value->checkbox4_2 === false && $value->checkbox4_3 === false && $value->checkbox4_4 === false && $value->checkbox4_5 === false && $value->checkbox4_6 === false && $value->checkbox4_7 === false) && ($value->checkbox4_8 === true) && (sprawdzRegexTextInput($value->prawnieUzasadnionyInteres)) && (is_object($value->dokumentacjaOceny) || is_string($value->dokumentacjaOceny))
)
)
)
) &&
(is_string($value->panstwo)) && ($value->panstwoZListy === 'none') && ($value->panstwo !== '') && (sprawdzRegexTextInput($value->panstwo)
)
) &&
((is_int($value->panstwoid) && is_numeric($value->panstwoid)) || (is_bool($value->panstwoid) && $value->panstwoid === false)) &&
(is_bool($value->zmiana))
) {
echo "ok";
//nie robię nic
} else {
$flagaPanstwa = false;
}
} else {
$flagaPanstwa = false;
}
}

Resources