In Grid view: block delete last record

Hi guys,

Call for a trick here (without having to duplicate a grid + page rules):

When there is one record left in a Grid View, I want my Delete icon on the record to be hidden.

I created a Total Records field in the parent object, so I can add it to the child grid records, but than I am stuck on how to use it to hide the Delete icon.
:thinking: :unamused_face:

tks for any help Knacksters!

Try something like this, changing it to your view:

$(document).on(‘knack-view-render.view_XXX’, function(event, view) {
let $gridRows = $(#${view.key} table tbody tr);
let $deleteButtons = $(#${view.key} .kn-link-delete); // Knack delete button class

if ($gridRows.length < 2) {
    $deleteButtons.hide(); // Hide delete buttons
} else {
    $deleteButtons.show(); // Show delete buttons
}

});

1 Like

Thks Leigh!

It works! with Perplexity tweeking it with .kn-table.

$(document).on(‘knack-view-render.view_2803’, function(event, view) {
let $gridRows = $(#${view.key} .kn-table tbody tr);
let $deleteButtons = $(#${view.key} .kn-link-delete);

if ($gridRows.length <= 1) {
$deleteButtons.hide();
} else {
$deleteButtons.show();
}
});

Tks! if nobodies has a no-code trick, I’ll take it! and actually will apply it in some other older cases.

That simplify a lot in comparaison to no-code.

And this is the code to apply it to various views:

$(document).on(‘knack-view-render.view_2803 knack-view-render.view_2419’, function(event, view)
{
let $gridRows = $(#${view.key} .kn-table tbody tr);
let $deleteButtons = $(#${view.key} .kn-link-delete);

if ($gridRows.length <= 1) {
$deleteButtons.hide();
} else {
$deleteButtons.show();
}
});

1 Like