3

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)
}
Jayesh Goyani
  • 11,008
  • 11
  • 30
  • 50
I Love Stackoverflow
  • 6,738
  • 20
  • 97
  • 216
  • if you are providing the names as literal strings then you don't need the `#= property #` just provide the string eg. `Delete(#=id#, 'Grid1');`. On a side note is there a reason why you are creating the delete command rather than using the grid's inbuilt delete command? – David Shorthose Nov 17 '15 at 13:05
  • @DavidShorthose:In my grid i have 1 column named "Action".Now in this action column i need to put 2 image named as Edit,delete.So is this possible to put image in command option and with edit option i dont want to perform inline editing or pop up editing.so is this possible? – I Love Stackoverflow Nov 18 '15 at 03:23
  • So for editing do you want this to navigate to another page/view or do you want it to bind to an edit template outside of the grid but on the same page? – David Shorthose Nov 18 '15 at 08:07
  • @DavidShorthose:For editing i want to open my records in edit mode on a new view i.e on new page – I Love Stackoverflow Nov 18 '15 at 08:32

1 Answers1

1

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.

Jayesh Goyani
  • 11,008
  • 11
  • 30
  • 50