Our blazing fast Grid component built with pure JavaScript


Post by gvats »

can i create a template column with onclick event just like i have onClick with widget column

Post by Maxim Gorkovsky »

Hello.
I'm sorry, it is not entirely clear what do you want to implement. Please be more specific.

Post by gvats »

ok

first of all can i achieve a functionality like can i have last column with edit and save button for each row like as in attached jped "template column with icons". ?
if yes please suggest some approach .

also i was trying to create a template with onClick event to capture the click on template column
{
      type: 'template', flex: 0,width:10, resizable: false, template: () => `
      <button class="btn"><i class="fa fa-save"></i></button>`
    }
we have widgets with onClick events
 {
            type    : 'widget',
            field   : 'city',
            text    : 'WidgetColumn',
            width   : 140,
            widgets : [{
                type    : 'button',
                cls     : 'b-raised',
                text    : 'Hello',
                onClick : ({ source : btn }) => {
                    const { record } = btn.cellInfo;
                    Toast.show(`Hello ${record.name} from ${record.city}`)
                }
            }]
can i have such onClick event with template column too , if not can i specify " widgets : [{
type : 'button'," this type button to be instead of type icon maybe?
Attachments
template column with icon.jpg
template column with icon.jpg (17.39 KiB) Viewed 1233 times

Post by Maxim Gorkovsky »

You can use cellclick event on the grid.
new Grid({
  listeners : {
    cellclick : ({ grid, record, column, target, event }) => {
      console.log(target); // logs clicked button
    }
  }
})
You might want to configure column to be readonly, to allow fast clicking
{
      type: 'template',
      flex: 0,
      width:10,
      resizable: false, 
      editor: false,
      template: () => `
      <button class="btn"><i class="fa fa-save"></i></button>`
    }
    
Also if you want to wrap code you can use code tag (in brackets)

Post Reply