sd1337 / adminlte-2-react

49 stars 24 forks source link

onClick event not working inside datatable #13

Closed andreguilhon closed 5 years ago

andreguilhon commented 5 years ago

Hello, I'm trying to write a DataTable to show records that I fetched from some API. I can list it without problems. My next desired step would be to put a button to delete the item listed. Although I could show the button, I can't make the onClick event on that button work. The code I'm using is bellow.

<Content title="Adicionar Eventos do robô" browserTitle="BackOffice">

          <Row>
            <Col xs={12}>
              <Box title="Listagem de eventos" type="primary" header={adicionar} footer={adicionar} >

                            <DataTable
                              responsive="true"
                              id="robot-event-list"
                              columns={ [ {title: "Robô", data: "robot_name"},
                                          {title:"Tipo de comando", data: "command_type"},
                                          {title: "Validade inicial", data: "valid_from"},
                                          {title: "Validade final", data: "valid_until"},
                                          {title: "Data da execução", data: "execution_date"},
                                          {title: 'Actions', render: (data) =>  <Button text="Action" onButtonClick={()=>{ alert('a') }  } ><Button text="dentro" onClick={()=>{ alert('a') } }></Button></Button>}
                                      ]}
                              options={{
                                select: false,
                                rowId: "browser",
                              }}
                              data = { items }
                            />
              </Box>
            </Col>
          </Row>
          </Content>

How can I make it work?

andreguilhon commented 5 years ago

Ok, for anyone who gets here, that is how I solved it:


                              responsive="true"
                              id="robot-event-list"
                              columns={ [ {title: "Robô", data: "robot_name"},
                                          {title:"Tipo de comando", data: "command_type"},
                                          {title: "Validade inicial", data: "valid_from"},
                                          {title: "Validade final", data: "valid_until"},
                                          {title: "Data da execução", data: "execution_date"},
                                          {title: 'Actions', data: null, render: () =>  <Button text="Action" className="on-click-eveent" /> }
                                      ] }
                              options={{
                                select: false,
                                rowId: "browser",
                              }}
                              data = { items }
                              onClickEvents={{
                                onClickEveent: (data, rowIdx, rowData) => {
                                  alert(data.robot_name);
                                }
                              }}
                            />```

className and the name of the function in the onClickEvents must be the same! 
Thanks to https://github.com/sd1337/adminlte-2-react-examples which had a working example!