Author Topic: External button  (Read 3767 times)

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
External button
« on: March 06, 2019, 01:12:46 am »
Hello,

I am using paramquery form as details table.

I want to post both my form and grid with a single button.
https://yadi.sk/i/7efYV49XKLBeVA

It is possible to operate the Grid function from the outside?

https://yadi.sk/i/DuspqD3ZZRaVAw


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: External button
« Reply #1 on: March 06, 2019, 08:49:12 am »
There is nothing like calling function from inside or outside the grid. Any method in the grid can be called as long as there is reference to the grid.

Code: [Select]
grid.method_name();

If you want to save your form data in grid, then addRow or addNodes method can be used.

https://paramquery.com/pro/api#method-addNodes

If you want to post changes in the grid to remote server, then get the changes with getChanges method and post them with jquery ajax call.

https://paramquery.com/pro/api#method-getChanges

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Re: External button
« Reply #2 on: March 07, 2019, 11:22:15 pm »
Hello,

I want to do this.

I add the following code to the example at this address.  "https://paramquery.com/pro/demos/editing_batch"

HTML
Code: [Select]
<div id="grid_editing" style="margin: auto;"></div>

<button onclick="saveChanges();">Save Button</button>

Click "Save Button". Console Message:
Code: [Select]
Uncaught ReferenceError: saveChanges is not defined at HTMLButtonElement.onclick (editing_batch:1) onclick @ editing_batch:1

How can I solve this problem?

There is nothing like calling function from inside or outside the grid. Any method in the grid can be called as long as there is reference to the grid.

Code: [Select]
grid.method_name();

If you want to save your form data in grid, then addRow or addNodes method can be used.

https://paramquery.com/pro/api#method-addNodes

If you want to post changes in the grid to remote server, then get the changes with getChanges method and post them with jquery ajax call.

https://paramquery.com/pro/api#method-getChanges

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: External button
« Reply #3 on: March 08, 2019, 07:41:55 am »
It's because the saveChanges function scope ( defined in that demo ) is within the closure whereas inline added functions to html are called in global window scope.

So please change this

Code: [Select]
function saveChanges() {

to this

Code: [Select]
window.saveChanges = function() {

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Re: External button
« Reply #4 on: March 08, 2019, 04:24:24 pm »
Thanks Param. Worked  :)

It's because the saveChanges function scope ( defined in that demo ) is within the closure whereas inline added functions to html are called in global window scope.

So please change this

Code: [Select]
function saveChanges() {

to this

Code: [Select]
window.saveChanges = function() {