This is a migrated thread and some comments may be shown as answers.

[Solved] Send rowindex using ClientTemplate

6 Answers 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gerard Eikelboom
Top achievements
Rank 1
Gerard Eikelboom asked on 17 Feb 2011, 01:41 PM
Hi,
To build the grid as we want to we use the onRowDataBound function.
This causes the grid to be very slowly.
So what you recommended us is to move all this and make use of clienttemplate.
I already move 50% of the code to the grid so, thanks for that.
But now I have another issue see the line below:
.ClientTemplate("<#if(AanregID == 0){ #> <input type='button' disabled='true' value=' ' class='bestelbuttondisabled'/> <# }else { #> <input type='button' onclick='ShowBestelPopupBox(<#=BesteldAantal#>, <#=SteelPrijs#>, <#=AanregID#>)' value=' ' class='bestelbutton'/> <# } #>");
This line works fine. The picture is shown Enabled or disabled.
The only thing that is not correct is ShowBestelPopupBox(<#=BesteldAantal#>,<#=SteelPrijs#>, <#=AanregID#>)
The function is hit and SteelPrijs & AanregID are correct filled out.
BesteldAantal = 0 because this is not filled out.
This is a textbox before this column in the grid.
How can I retrieve this one at the moment i do the onclick?

Another question. Is it possible to for example onclick='test(RowIndex)'? Give the rowindex with the method using clienttemplate?

Regards,
Gerard

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 17 Feb 2011, 02:11 PM
Hello Gerard Eikelboom,

 The easiest way is to modify your ShowBestelPopupBox function to receive an instance of the button

onclick='ShowBestelPopupBox(this, <#=SteelPrijs#>, <#=AanregID#>)'

Then use the argument to find that textbox and get its value:

function ShowBestelPopupBox(button, SteelPrijs, AanregID)
{
      var tr = $(button).closest("tr");
      var textbox = tr.find(":text");
      var BesteldAantal = textbox.val();
}

Regards,
Atanas Korchev
the Telerik team
0
Gerard Eikelboom
Top achievements
Rank 1
answered on 17 Feb 2011, 02:26 PM
Hi Atanas,
When I use your example I get an array of 200(grid size) in BesteldAantal  returned
Here is my textbox where I fill out the number i want to order:
.ClientTemplate("<input type='text' class='besteldaantal' name='BesteldAantal' onclick='ShowProductDetails(<#= artikelID #>)' />");

When I check for BesteldAantal [index].value it gives me the correct ordered number.
But then I need the index.
What is does it also shows an popup at onclick (javascript) And with rowindex I calculate where I have to set that popup. So if possible the row index would help me a lot.

Regards,
Gerard
0
Atanas Korchev
Telerik team
answered on 17 Feb 2011, 03:16 PM
Hi Gerard Eikelboom,

 The row index can be retrieved like this:

function ShowBestelPopupBox(button, SteelPrijs, AanregID)
{
      var tr = $(button).closest("tr");
      var rowIndex = tr[0].rowIndex;
}

However I still think that my code should have worked. Is the "tr" the right one at all? 

Regards,

Atanas Korchev
the Telerik team
0
Gerard Eikelboom
Top achievements
Rank 1
answered on 17 Feb 2011, 03:23 PM
Atanas,

Here is my function what I have:

function ShowBestelPopupBox(button, j, k) {
    var tr = $(button).closest("tr");
    var rowIndex = tr[0].rowIndex;
    var textbox = tr.find(":text");
    var BesteldAantal = textbox.val();
When I set a breakpoint rowIndex =undifined, textbox  = undefined BesteldAantal =array(200)
So I don't know what goes wrong.
Also button is undefined when I try to read it.

Regards,
Gerard
0
Gerard Eikelboom
Top achievements
Rank 1
answered on 17 Feb 2011, 03:28 PM
Atanas,
I don't know but it works, just the way you said.
So the solution is correct. i don't now why but the values I receive are now the right ones. Herefore they where empty.

Thanks,
now i can finish and put the rest in the clienttemplates.

thanks again,
Gerard Eikelboom
0
Atanas Korchev
Telerik team
answered on 17 Feb 2011, 03:30 PM
Hi Gerard Eikelboom,

The problem is that "button" is undefined.  Did you change the client template to pass the button? It should be like this. 

<input type='button' onclick='ShowBestelPopupBox(this, <#=SteelPrijs#>, <#=AanregID#>)

Regards,
Atanas Korchev
the Telerik team
Tags
Grid
Asked by
Gerard Eikelboom
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Gerard Eikelboom
Top achievements
Rank 1
Share this question
or