Author Topic: Why do we have to create a different object each time?  (Read 99 times)

necatiozbek

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 19
    • View Profile
Why do we have to create a different object each time?
« on: July 17, 2024, 02:06:36 pm »

Hi;

Why do we have to create a different object each time? Can't we use the grid object we first created? Can't we add new data and refresh the view?
How will this happen for a popUp grid that opens multiple times, many times, from different methods?

Please review the project below.

My Project Angular js file:

(function ()
{
    angular
        .module("Keyiflice", [])
        .controller("FaturalarController", ['$scope', '$http', '$cookies', '$filter', '$window', '
            function ($scope, $http, $cookies, $filter, $window) {

          var vm = this;

          var pg_gridobj = {
                        width: "auto",
                        height: 200,           
                        scrollModel: { autoFit: true },
                        menuIcon: true,
                        strNoRows: 'Kayıt Bulunamadı',
                        location: 'local',
                        editable: false,
                        title: "Faturalar",
                        scrollModel: { autoFit: true },
                        selectionModel: { type: 'row', mode: 'block' },

                        colModel: [ { title: "İşlTipi", dataIndx: "ISLEM_TIPI"}] ,

                        //calculate summary upon these 2 events.
                        dataReady: calculateSummary,
                        change: calculateSummary,
                        summaryData: calculateSummary,
                        dataModel: { data:[] }                    // At the beginning, I open the grid data empty.
                    };


             var gridfatura_1 = pq.grid("#grid_array", pg_gridobj );  // <   While the page is loading, initially, I created a grid object here



             // My other function in the project

             vm.Data_Bind=function()
             {

                  gridfatura_1.dataModel.data=result.data;
                  gridfatura_1.refreshDataAndView();           // <   Even though it is the grid I created at the beginning, the code does not give an error, but the data is not visible. not refresh

                 // but below code works and data is seen in grid

                  var gridfatura_2=$("#grid_array");
                        gridfatura_2.pgGrid("option","dataModel",{data:result.data});
                        gridfatura_2.pgGrid("refreshDataAndView");

             }

            vm.Other_2=function()
            {

               var gridfatura_3 ... < Will we always create another object?         
            }

            vm.Other_3=function()
            {

               var gridfatura_3 ??? < Will we always create another object?             
            }




}])
})(angular);

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6307
    • View Profile
Re: Why do we have to create a different object each time?
« Reply #1 on: July 17, 2024, 05:28:10 pm »
No you don't have to create a new object every time to call API.

Please correct this

Code: [Select]
gridfatura_1.dataModel.data=result.data;

to

Code: [Select]
gridfatura_1.option('dataModel.data', result.data);