Display a view in Javascript

I am able to not display a table when it is empty I would like to display a view (view_217) at the same time and not display it when the table has data. Here is the code I tried, but it doesn’t work

$(document).on(‘knack-scene-render.scene_5’, function(event, scene) {
// Loop through each scene view, on the page.
scene.views.map(function(view) {
if(Knack.models[view.key] && Knack.models[view.key].data && Knack.models[view.key].data.length < 1) {
// Remove the specific view.
$(’#’ + view.key).remove();
$(’#view_217’).show();
}
if(Knack.models[view.key] && Knack.models[view.key].data && Knack.models[view.key].data.length > 1) {
$(’#view_217’).remove();
}
});
});

Thanks

Hello Nancy,

Because this loop also run for view view_217

Need to exclude that view from loop.

Regards,
sunny Singla

Thanks.

But how can I check if a table in a certain view has no data?

$(document).on(‘knack-view-render.view_13’, function (event, view, data) {
if(Knack.models[view.key] && Knack.models[view.key].data && Knack.models[view.key].data.length < 1) {
// Remove the specific view.
$(’#’ + view.key).remove();
});
});

try below code
$(document).on(‘knack-scene-render.scene_5’, function(event, scene) {

// Loop through each scene view, on the page.

scene.views.map(function(view) {

if(view.key!=“view_217”)

{

if(Knack.models[view.key] && Knack.models[view.key].data && Knack.models[view.key].data.length < 1) {

// Remove the specific view.

$(’#’ + view.key).remove();

$(’#view_217’).show();

}

if(Knack.models[view.key] && Knack.models[view.key].data && Knack.models[view.key].data.length > 1) {

$(’#view_217’).remove();

}

}

});

});

1 Like

Thanks a lot! You save my project!

1 Like