Tip: VueTable Button Actions
In the VueTable, you can add your own columns, in this example, we have a added a normal button, conditionally rendered the labels and color depending on some value in the row.
The column name is "check" and the header label is "Check"
We add out button via the database-fields property. IT DOES NOT EXIST IN OUR DATA-BASE though.
and the title.
We then indicate that its a "Button".
We also give it an initial color
You can also indicate from here that the color is from the row content. e.g. Lets assume that the color of the button is in the field named buttoncolor, then here, we would write
check: item.buttoncolor
We want the label of the "button" to be dependent on some row value. We then define a "pre-display" computation via the Compute Value property.
This means that each 'value' of the button will be determined by the callback
checklabel. We add
() to this computation because we want that callback to receive the whole row data. Notice the
checklabel(item As Map) below. If we wanted the computation to use the actual value of the 'check' field, we would exclude the () from the call and just write
checklabel(currentLabel As String). Map with () and String without.
Sub checklabel(item As Map) As String
Dim carbs As Int = item.GetDefault("carbs", 0)
carbs = banano.parseInt(carbs)
If carbs <= 50 Then
Return "Decline"
End If
If carbs >= 51 Then
Return "Approve"
End If
Return "Check"
End Sub
From this sub, if the value of cards, is <= 50 then decline, then if >= 51 then approve. The last return is just added for completeness.
We also want the color of the button to be computed based on some property.
Here we say, for the check 'button', if the value is <= 51, make the button color red and if not, make it green. Note the lowercase color value.
Sub checkcolor(item As Map) As String
Dim carbs As Int = item.GetDefault("carbs", 0)
carbs = banano.parseInt(carbs)
If carbs <= 50 Then
Return "red"
End If
If carbs >= 51 Then
Return "green"
End If
Return "black"
End Sub
Just in case, we also register these methods on the Vue Component instance.
Events
The event fired by this button click is defined as
sub dtTable_check (Item As Map)
This will be available in the Kitchen Sink Data-Table Examples.