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

Custom Button to call php API in main form or any alternative option

1 Answer 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kanwar
Top achievements
Rank 1
Kanwar asked on 13 Sep 2013, 04:19 AM
Hi I've got a php form that I've modified with a Kendo Grid. (Please see attachment below).

What I would like to do

a) Invoke a PHP function on Click of the Custom Button in the Grid.
b) Pass value from javascript/ajax back to the PHP page such that it recognizes it as a Post when the button is clicked.
c) The function in PHP in turn calls a Cloud API , want to invoke this cloud API from the same button click function.

Thanks
Kanwar Batra

PS : This is the last validation step for me to confirm to my customers and peers to use your interface without this we are unable to move forward

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 16 Sep 2013, 01:08 PM
Hello Kanwar,

Basically to invoke a function from a button in the Grid can be achieved in several ways:
  1. Create command button like explained here:
    http://demos.kendoui.com/web/grid/custom-command.html
  2. Use template (the link included an example how to Invoke JS function) column to create the button on your own and invoke a JavaScript function passing the parameter to it. 
    e.g.
    "<buttom class='myClass' onclick='someFunction(#= ColumnNameThatYouNeed#)'>Some Text that you want</button>"


    <script>
          function someFunction(theId){
               //... perform your own $.post here
          }
    </script>


  3. Create template button like above with a class and use delegate event to handle it with combination of the dataItem method of the Grid. 
    e.g.
    template: "<button class='mySpecialButton'>Some Button again</button>"
     
    ....
     
    <script>
        $('#gridName').on('click','.mySpecialButton',function(e){
             var model = $('#gridName').data().kendoGrid.dataItem($(this).closest('tr'))
             //... perform your own post again
         }
    </script>

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Kanwar
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or