Ok, this is a little bit strange.
I would first check the following things…
Check my DATABASE —> are the same items in my LIVE-Database as in Previewmode? (Databases are synced?)
Because if not, perhaps you look at the preview-database, which can have 446-items, but your live database is empty. Or vise versa.
Check also the database-permissions, perhaps they block your code.
Check Read & Write options (already mentioned by J.D.).
Delete all other code, like J.D. said before and just do a simple test with related code-part.
Perhaps take a look again at my example, which works without any errors again and try to reconstruct exactly the same situation.
Also check the right options and connection of your dataset.
And if nothing helps, than i would do the next step and post it into “rolling out improvements”.
@russian-dima all options above checked and normal, as expected. Also, running your latest code I get this:
An error occurred in one of datasetReady callbacks TypeError: Cannot read property ‘toString’ of null
And againl: why would the let count = $w( “#dataset1” ).getTotalCount(); work inside the export function and not in the on.Ready()??
export function table1_dataChange(event) {
let count = $w("#dataset1").getTotalCount();
console.log(count) <-- THIS ONE GIVES ME 445, ALL GOOD.
$w("#counter").text = String(count);
}
export function table1_dataChange(event) {
let count = $w("#dataset1").getTotalCount();
console.log(count)
$w("#counter").text = String(count);
}
$w.onReady (function() {
$w("#dataset1").onReady(() => {
let count = $w("#dataset1").getTotalCount();
console.log(count)
$w("#counter").text = count.toString()
if ($w("#counter").text === "29") {
$w("#text29").show();
}
else {
$w("#text26").show();
}
})
});
export function hoverZone_mouseIn(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w('#hoverEfarmostiki').show();
$w('#checkbox2').hide();
$w('#vectorImage3').hide();
$w('#hoverBox').show();
}
export function hoverZone_mouseOut(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w('#hoverEfarmostiki').hide("fade");
$w('#checkbox2').show("fade");
$w('#vectorImage3').show("fade");
$w('#hoverBox').hide("fade");
}
export function hoverzoneEfarm1_mouseIn_1(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w('#hoverYpoyrgeio').show();
$w('#hoverboxYpoyrgeio').show();
$w('#hoverzoneEfarm').hide();
}
export function hoverzoneEfarm1_mouseOut(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w('#hoverYpoyrgeio').hide("fade");
$w('#hoverboxYpoyrgeio').hide("fade");
$w('#hoverzoneEfarm').show("fade");
}
export function hoverzoneIsxyon_mouseIn_1(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w('#hoverboxIsxyon').show();
$w('#hovermainIsxyon').show();
$w('#vectorImage2').hide();
$w('#checkbox1').hide();
}
export function hoverzoneIsxyon_mouseOut_1(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w('#hoverboxIsxyon').hide("fade");
$w('#hovermainIsxyon').hide("fade");
$w('#vectorImage2').show("fade");
$w('#checkbox1').show("fade");
}
I would suggest you to create a second dataset (“dataset2”) and connect it with your Database (“LawDatabase”). It can be setted-up to “Read-Only”.
Did you set the Database-permissions to “everyone” ?
Run the given code (you have just to open the site) and look what does the console say?
If you get already an error or you have “null-result”, try to make a more simple DATABASE with just the given “title” field and put 3-10 items into it.
Connect your dataset, with this new DATA-COLLECTION, run the code again.
Did something changed, or still no results?
EDIT: DEACTIVATE all your OLD-CODE before you do the test.
You can do it when you comment out your code like this…
Start to comment out CODE ----> /*
…
all CODE here will be commented out and gets deactivated.
…
@russian-dima Ok, the code above works in another test dataset. It returns to console the correct number of items in the dataset. But in my main dataset, it returns null . All permissions are set to anyone.
@russian-dima actually it’s Greek. I won’t even enter an investigation whether unicode affects JS execution (???). I’d rather quit the whole project. Thanks for everything, the last 3 days!
I didn’t fix it.
But if I delete this filter, my dropdown menu stops working… How can I include both my datasets in the on.Ready()? I mean, what would be the syntax?
To complete this thread, I’d like to report that I solved my problems, most probably in a quite unorthodox way.
Since the export function to get me all items counted in my dataset1 was working, I thought just to try to embed my conditionals just below it and do not mess with the on.Ready(), due to problems found with the connection between my 2 datasets.
So I ended up with this:
export function table1_dataChange(event) {
let count = $w("#dataset1").getTotalCount();
console.log(count)
$w("#counter").text = String(count);
if ($w("#counter").text === "1") {
$w("#text25").show();
$w("#text12").hide();
} else {$w("#text12").show();
$w("#text25").hide();
}
}
Smart or dumb, I don’t know, but it finally works. Thanks J.D. and russian-dima for your efforts.
I don’t understand why a filter should change or affect onto the code.
Just right from the beginning.
You have a DATABASE where you have some items in it.
This DATABASE is connected with a DATASET. (let us say all settings are ok).
Now the action which you want to achieve, let us say the following…
a) You want to count the items right from the beginning when page has loaded.
b) You want to show the result of this counter in a textfield (let us call it “TXTcounter” ).
c) You want to show up a Textfield when some special counting-numbers are given, let us say you have 448 -items in your DATABASE.
Now you start coding (after you have setted-up and connected your DATASET correctly).
When page & dataset is ready —> get the number of items in my data-collection…
Of course, first we define a new variable (“count”) and then fill it with the counting result of the amount of database-items. And we also do not forget to make a little CONSOLE-LOG !
$w.onReady (function() {
$w("#dataset1").onReady(() => {
let count = $w("#dataset1").getTotalCount()
console.log("My total items in DB = " + count)
})
})
Now we want to fill the Textfield —> “TXTcounter” with the founded counting result…
OKEYYYYYY, well done.
Then i stop here . I just wanted to show you the way, how i would try to solve the problem. But you got it already!
@russian-dima Thanks my friend. Just for the sake of it, the steps are these (copy-paste from you, above):
You have a DATABASE where you have some items in it. as a matter of fact, I have 2 connected databases through a reference field.
This DATABASE is connected with a DATASET. (let us say all settings are ok). for each DB collection I’ve set up a dataset on the page in order to be able to use dataset2 values to filter (dropdown) dataset1 values. I followed the tutorials for this.
Now the action which you want to achieve, let us say the following…
To achieve this, I add a filter to Dataset1 based on the referenced field in Dataset2 (‘includes’ relationship). Dataset2 values are also values of a dropdown. So when I select a value from this dropdown, the whole Dataset1 is filtered based on this value (it’s the Actors and Movies tutorial, somewhere).
So, strangely enough, if I delete this filter, in other words, if I delete the connection between 2 datasets, your code and J.D. code was working fine (the on.Ready()) part. But if I do this, I justcan’t filter my records any more.
So since theexport functionwas already working to count the total number of items, I crossed my fingers and decided to put the if-else and .show - .hide just below it.