简体   繁体   中英

How to pass hardcoded string value from javascript onclick with template option using kendo ui grid?

I am having 2 grids on my page with name grid1 and grid2 .

Now i want to pass grid name as hardcoded to my 1 common javascript function for deleting records from grid like below:

for Grid 1 delete function:

field: "Id",
template:<a  title="delete" onclick="javascript:return Delete(<#=Id#>,<#=grid1#>);" > //showing error in console  grid1 is not defined

for Grid 2 delete function:

field: "Id",
template:<a  title="delete" onclick="javascript:return Delete(<#=Id#>,<#=grid2#>);" > //showing error in console  grid2 is not defined.

My javascript function:

function Delete(id, gridname) {
        console.log(id,gridname)
}

Please try with the below code snippet. If you write any text between # (hash) the grid try to find that field in your datasource that's why you got the undefined error.

JS Function:

function Delete(id, gridname) {
            var grid = $("#" + gridname).data("kendoGrid");
            console.log(id, gridname)
}

for Grid 1 delete function:

field: "Id",
template: "<a title='delete' onclick='javascript:return Delete(\"#:Id#\",\"grid1\");'></a>",

for Grid 2 delete function:

field: "Id",
template: "<a title='delete' onclick='javascript:return Delete(\"#:Id#\",\"grid2\");'></a>",

Let me know if any concern.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM