I am having trouble in calling typescript method on button click in SPFx with no JavaScript framework.
for Example:
private _renderListCustomer(items:ISPListCustomerItem[]):void{
let html:string=`<table width='100%' border=1 id="tblEmployees" class="table">`;
html+=`<thead>
<th scope="col">Customer Id</th>
<th scope="col">Name</th>
<th scope="col">Address</th>
<th scope="col">Type</th>
<th scope="col">Update</th>
</thead><tbody>`;
debugger;
type NewType = ISPListCustomerItem;
items.forEach((item:NewType)=>
{
html+= `<tr>
<td>${item.CustomerID}</td>
<td>${item.CustomerName}</td>
<td>${item.CustomerAddress}</td>
<td>${item.CustomerType}</td>
<td><button id="${item.ID}" item-id="${item.ID}" type="submit" class="update btn btn-primary" data-toggle="modal" onClick=${this.BindItem(item.ID)} data-target="#DivUpdateItem">Update</button></td>
</tr>`;
});
html+=`</tbody></table>`;
const listContainer:Element=this.domElement.querySelector("#spListContainer");
listContainer.innerHTML=html;
}
Method to called
// Id:number
public BindItem(id:number):void{
pnp.sp.web.lists.getByTitle("Customers").items.getById(id).select("*,CustType/Id,CustType/CType").expand("CustType").get().
then((item:ISPListCustomerItem)=>{console.log(item);
document.getElementById('txtTitleUpdate')["value"]=item.Title ,
document.getElementById('txtCustomerIDUpdate')["value"]=item.CustomerID,
document.getElementById('txtCustomerAddressUpdate')["value"]=item.CustomerAddress,
document.getElementById('txtCustomerNameUpdate')["value"]=item.CustomerName,
document.getElementById('txtCustomerTypeUpdate')["value"]=item.CustomerType,
document.getElementById('ddlCustTypeUpdate')["value"]=item.CustType.ID}).
catch((error)=>{ alert(error); error; })
}
But method is not getting called on button click.
Any help would be appreciated, thanks in advance.
type="button"
instead oftype="submit"
?