frappe / datatable

The Missing Javascript Datatable for the Web
https://frappe.io/datatable
MIT License
1.02k stars 164 forks source link

Question: How to add Actions? #91

Open Mashiane opened 4 years ago

Mashiane commented 4 years ago

Hi there

How can I add actions for each row, for example have 2 icons / buttons for Edit/Delete with events linked to them so that when I click on one, it actions the appropriate event called?

Thanks

saru2020 commented 2 years ago

also, there's no way to get an event callback whenever a cell is tapped/clicked? (Considering checkbox is hidden)

hiravesonali commented 2 years ago

Is there a possibility to add buttons or actions on each row? I also need to do it.

grmru commented 1 year ago

+1 I also need similar functionality.

Harikarthyk commented 1 year ago

+1 I also need similar functionality

Madcheese101 commented 3 months ago

you can do something like this:

EXAMPLE:

let button_formatter = (value) => `<div class="print-item" doc-name-value="${value}">Print</div>`

the doc-name-value attribute can be anything meaningful to you that you want to use in the print function later on

the (value) bit can be changed to pass other information like this (value, columns, column, row_data)

The columns parameter will get you all the columns of the row with detailed info such as column settings and html content The column parameter will get you the settings of this column The row_data parameter will get you the initial/original row data that you passed when initializing the datatable or using datatable.refresh()

please note:

_**1. you can name the parameters whatever

  1. I don't know how to ask for specific parameters, so I just pass them all if I just want the rowdata parameter**

after that, you need to create a column for that button and set the format: parameter value to the button_formatter variable

const columns = [ ....
    // print_btn
     ,{
        name: ' ',
        id: 'name_to_print',
        editable: false,
        resizable: false,
        dropdown: false,
        format: button_formatter
     },
    ....
]

after that you can attach an event to the button with jQuery using the button class which is in this case is: print-item