user2656129
user2656129

Reputation: 51

Disable button inside bootgrid dynamic

Now i have a bootgrid table to download files using bootgrid.I have written a formatter for that and it works well.

"commands": function(column, row) {
    return '<a href="'+row["slink"]+'"><button type="button" class="btn btn-info " data-row-id="' + row.id + '">Download</buttn></a> ';
}

Where slink gives the download location of file for corresponding row with row id id..

Now the problem is that some rows dont have any files and row[slink] will return blank.When user clicks a blank row the page just refresh.

Now what i want to do is to disable the download button when the slink value is blank.How can i achieve this? It would be greatif i could change the button text from download to something like Not available it would be great.

Upvotes: 1

Views: 178

Answers (1)

Alisson Reinaldo Silva
Alisson Reinaldo Silva

Reputation: 10705

In order to fix your problem, replaces your formatter with this:

"commands": function(column, row) {
    if (row["slink"] == null || row["slink"] == '')
        return "";
    return '<a href="'+row["slink"]+'"><button type="button" class="btn btn-info " data-row-id="' + row.id + '">Download</buttn></a> ';
}

We just check if the row has an empty or null slink. If it has, we return an empty string instead of an <a></a> tag.

Upvotes: 1

Related Questions