Is it possible to check the visibility of the particular datatable row?
I found only isColumnVisible and getVisibleCount, but both of them are irrelevant and as far as I can see, there's no such solution for the rows.
How can I do such thing? For instance, after the filtering I can get all data items, but that's all. It's the only idea I've come up with:
onAfterFilter:function(){
var dataId = this.data.pull;
var keys = Object.keys(dataId);
for (var i = 0; i < keys.length; i++){
console.log(this)
}
}
http://webix.com/snippet/c6ecdcd5
Ok it feels like a long way of doing this. And I've not done anything other than just get it to work.
But you will find all of the ids you need in this.data.order so the following code puts all the filtered items into filteredObjs
var dataId = this.data.pull;
var keys = Object.keys(dataId);
var filteredIds = this.data.order;
var filteredObjs = [];
for (var i = 0; i < filteredIds.length; i++) {
for (var j = 0; j < keys.length; j++) {
if (filteredIds[i] === dataId[keys[j]].id) {
filteredObjs.push(dataId[keys[j]]);
}
}
}
console.log(filteredObjs);
Not saying its perfect. But its a start...
For starters you need to change console.log(this) to console.log(keys[i])
As an alternative to the data-based solution made by #ShaunParsons I found that it's possible to check the visibility through the getItemNode function, as the nodes of the invisible items are undefined.
http://webix.com/snippet/4f31a5b5
onAfterFilter:function(){
var dataId = this.data.pull;
var keys = Object.keys(dataId);
for (var j = 0; j < keys.length; j++) {
console.log(this.getItemNode(keys[j]))
}
}
Related
I have a website that has a "list" content block set up with the correct accessibility roles assigned to the parent and children.
However, lists can also be added through the WYSIWYG block.
Therefore I have the below code to ensure these also receive the correct roles.
var lists = document.querySelectorAll("ol, ul");
for (var i = 0; i < lists.length; i++) {
lists[i].setAttribute("role", "list");
}
var lists = document.querySelectorAll("li");
for (var i = 0; i < lists.length; i++) {
lists[i].setAttribute("role", "listitem");
}
What I want to do to make it as efficient as possible is to check that the ordered or unordered lists don't have a role before applying that code however I can't get this working. I am trying the below but with no luck.
if (document.querySelector("ol, ul") && ![role="list"]) {
var lists = document.querySelectorAll("ol, ul");
for (var i = 0; i < lists.length; i++) {
lists[i].setAttribute("role", "list");
}
var lists = document.querySelectorAll("li");
for (var i = 0; i < lists.length; i++) {
lists[i].setAttribute("role", "listitem");
}
}
Can someone explain why this isn't working please?
I am getting old or just rusty or both, but I hang my head in shame as I bring this here because there must be something really, really simple that I am missing.
I am writing this using Google Apps script in Sheets.
Why does this fail once I reach j = 2? I have tried declaring the array in every different way I can think of, nothing gets past j=2. Wth am I missing? It's something dumb I know it.
function myFailure() {
for (var j = 0; j < 10; j++) {
for (var k = 0; k < 31; k++) {
var item = 'Item '+k;
let thisItem = new Array([],[]);
thisItem[j][k] = item; //the problem is happening here, once j=2 but why
console.log(j,k);
console.log(thisItem[j][k]);
}
}
}
myFailure();
Try this:
function myFailure() {
let thisItem = [];
for (var j = 0; j < 10; j++) {
thisItem[j] = []
for (var k = 0; k < 31; k++) {
thisItem[j][k] = `Item [${j}][${k}]`
console.log(thisItem[j][k]);
}
}
}
Partial Execution log
10:04:00 AM Info Item [0][0]
10:04:00 AM Info Item [0][1]
10:04:00 AM Info Item [0][2]
10:04:00 AM Info Item [0][3]
10:04:00 AM Info Item [0][4]
10:04:00 AM Info Item [0][5]
I have a bunch of comma-separated values stored as strings in a JSON file. My aim is to split these values to populate a select element which is based on Selectize.js. Code (excerpt) looks as follows:
var options = {};
var attr_split = data.attributes['Attribute1'].split(",");
var options_key;
for (var i = 0; i < attr_split.length; i++) {
options_key = attr_split[i]
}
var options_values = {
value: options_key,
text: options_key,
}
if (options_key in options)
options_values = options[options_key];
options[options_key] = options_values;
$('#input').selectize({
options: options,
});
Although this seems to work, the output in the select element only shows the last iterations done by the for loop. As per here
and here, I've tried
for (var i = 0; i < attr_split.length; i++) {
var options_key += attr_split[i]
}
but this throws me undefined plus all concatenated strings without the separator as per the following example:
undefinedAttr1Attr2Attr3
When I simply test the loop using manual input of the array elements everything appears fine:
for (var i = 0; i < attr_split.length; i++) {
var options_key = attr_split[0] || attr_split[1] || attr_split[2]
}
But this is not the way to go, since the number of elements differs per string.
Any idea on what I'm doing wrong here? I have the feeling it's something quite straightforward :)
when you declare 'options_key' ,you are not initializing it.so its value is undefined .when you concatenate options_key += attr_split[i] .in first iteration options_key holds undefined.so only you are getting undefinedAttr1Attr2Attr3.
so declare and initialize options_key like.
var options_key="";
and in your loop
for (var i = 0; i < attr_split.length; i++)
{
options_key = attr_split[i]
}
Everytime you replace options_key with value of attr_split[i].so after the loop it will contain last element value.corrected code is
for (var i = 0; i < attr_split.length; i++)
{
options_key += attr_split[i]
}
Just change var options_key; to var options_key="";
The reason you are getting undefined is because you have not defined the variable properly.
Here is a working example
var attr_split = "1,2,3,4".split(",");
var options_key="";
for (var i = 0; i < attr_split.length; i++) {
options_key += attr_split[i]
}
alert(options_key);
var options_values = {
value: options_key,
text: options_key
}
alert(options_values);
The following code executes on the press of a button. It works fine alerting one string of the getElementsByName array, but when introduced to a loop, it still only alerts the first string value, and nothing more:
function checkvals() {
var input = document.getElementsByName('ModuleTitle', 'ModuleCode', 'BuildingName', 'Day');
var i = 0;
for (i = 0; i <= input.length; i++){
alert(input[i].value);
}
}
That's because getElementsByName only accepts one argument, so it's only fetching the first name.
You can build a full collection like this...
var names = ['ModuleTitle', 'ModuleCode', 'BuildingName', 'Day'];
var input = [];
for(var i = 0; i < names.length; i++) {
var name_els = document.getElementsByName(names[i]);
for(var j = 0; j < name_els.length; j++) {
input.push(name_els[j]);
}
}
Then loop over the input Array, (or just do your work in the inner loop).
Additionally, you have a bug.
This...
for (i = 0; i <= input.length; i++){
should be this...
for (i = 0; i < input.length; i++){
...otherwise, you'll go one past the last index.
That's because getElementsByName only takes a single name argument, and returns all elements with that value for their name attribute. (See https://developer.mozilla.org/en/DOM/document.getElementsByName.) If you have multiple names to look up, you'll have to call it multiple times.
i have function:
function getFieldNames(arrayOfRecords) {
var theStuff;
for (var i = 0; i = arrayOfRecords.length - 1; i++){
theStuff = arrayOfRecords[i];
theList = theStuff.split('" ');
for (var j = 0; j = theList.length - 1; j++) {
var v = theList[j].split('="');
fName1[i][j] = v[0];
}
}
return fName1;
}
the argument arrayOfRecords is an array, and i dont know how to setup to the 'theStuff' variable an array element? When I do like it is above, i get something stupid.
can anyone help me? :)
There may be other problems but the one that leaps out at me is your for loop header:
for (var i = 0; i = arrayOfRecords.length - 1; i++)
The second part should be a condition, which when evaluated to false will stop the loop from running. What you probably wanted was:
for (var i = 0; i < arrayOfRecords.length; i++)
So when i is not less than arrayOfRecords.length, the loop will stop. Alternatively (to keep the - 1, but I tend to use the above version):
for (var i = 0; i <= arrayOfRecords.length - 1; i++)
The same goes for the nested loop.