Author Topic: Help need for context of grid object  (Read 3056 times)

TonyLeech

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 76
    • View Profile
Help need for context of grid object
« on: March 02, 2016, 03:17:52 am »
Please help me understand where I am going wrong with the context of objects in ParamQuery.  I am trying to call an external php from a button in the toolbar.

My toolbar is created like this...
                     toolbar: {
                        cls: 'pq-toolbar-export',
                        items: [
                           {
                              type: 'button',
                              label: "Create StockDiff",
                              icon: 'ui-icon-document',
                              listeners: [{
                                 "click": function () {
                                    var grid = $(this).closest('.pq-grid');
                                    var $selArray = $("#grid_php").pqGrid( "selection", { type: 'cell', method: 'getSelection' } );
                                    if ($selArray.length == 1) {
                                       var rowData = $selArray[0].rowData;
                                       createStockDiff(grid, rowData);
                                    }
                                 }
                              }]
                           }
And then my function is like this...
                  function createStockDiff(grid, rowData) {
                     var url, type;
                     var partnumber = rowData.partnumber;
                     var mrpqty = rowData.mrpqty;
                     var talliscan = rowData.total;
                     var adjustqty = talliscan-mrpqty;
                     type = 'document';
                     url = "createstockdiff.php?pq_createhtml=1";
                     $.ajax($.extend({}, ajaxObj, {
                        context: grid,
                        url: url,
                        data: { partnumber: partnumber, count: talliscan, mrpqty: mrpqty },
                        success: function (response) {
//                           this.refreshRow({ rowIndx: rowIndx});
                        },
                        error: function () {
//                           this.refreshRow({ rowIndx: rowIndx});
                        }
                     }))
                  }

The selArray, rowData and function call activate ok, but the ajaxObj here...
                  var ajaxObj = {
                     dataType: "JSON",
                     beforeSend: function () {
                        this.showLoading();
                     },
...reports "Object doesn't support property or method 'showLoading'.

I already use the ajax process in other parts of the code so I know it is ok, but I think I am not correctly passing the grid object to my function.
Would you be able to explain why I can't pass the grid object in this way and help me to better understand how ParamQuery works? It is obvious that I don't understand it at all.

I really hope you can help.

Many thanks.  Tony.


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Help need for context of grid object
« Reply #1 on: March 02, 2016, 01:04:55 pm »
Please refer this topic for difference between grid and $grid variables: http://paramquery.com/pro/tutorial#topic-special-vars

grid variable is incorrect in your code.

It can be obtained as

Code: [Select]
var grid = $("#grid_php").pqGrid( 'getInstance' ).grid;

TonyLeech

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 76
    • View Profile
Re: Help need for context of grid object
« Reply #2 on: March 10, 2016, 10:33:57 pm »
Thank you again for your help and for correcting my code.  Your direction to the tutorial page is very useful.  I am slowly beginning to understand...I hope.

Incidentally, and unrelated, in a previous help topic you mentioned an update release may be available from January.  Can you suggest when your next update will be?  The update I am waiting for is to include export of number format correctly to Excel (rather than all Text Only format).

Many thanks again for your reliable support.

Tony

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Help need for context of grid object
« Reply #3 on: March 14, 2016, 03:44:51 pm »
The new version v3.3.0 is available for download now.

TonyLeech

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 76
    • View Profile
Re: Help need for context of grid object
« Reply #4 on: March 14, 2016, 05:30:20 pm »
I saw that this morning, and I'm really looking forward to trying some of your new features.

I would like to say how much I think this is a fantastic tool.  I may not be the best at using it yet, but it allows me to produce an interface I could only have dreamed of with my limited skills for web/db development.  Thank you for making me look good.