Author Topic: compute cell values  (Read 2080 times)

Richard

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 41
  • Richard
    • View Profile
Re: compute cell values
« Reply #15 on: April 11, 2022, 05:07:14 pm »
Hi paramvir

I haven't tried the method you gave me today, but I'll try it.
Regarding the stock quantity calculation, I have to solve the following part, so I ask the question again.
I would really appreciate it if you could let me how to solve it.

1) For Stock quantity (C) on the first day of every month,
    I want to display the result of adding Day production and Night production to Stock quantity of the previous month (A)
    and subtracting Shipment quantity and Etc quantity.
    (As you konw, the stock quantity from the second day (D) of every month is displayed as the attached image shows the result of adding
      Day production and Night production to the previous day's stock quantity and subtracting Shipment quantity and Etc quantity)

2) In the Stock quantity (B) of this month (March in the attched image), I want to display the Stock quantity of the last day of this month.
« Last Edit: April 11, 2022, 05:15:58 pm by Richard »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: compute cell values
« Reply #16 on: April 12, 2022, 10:39:30 am »
What issue are you facing exactly? The way I see it, it's simple addition and subtraction of cell values and cell values are obtained from rowData[ dataIndx ], example of which I have shared already in previous post.

Please let me know if I've missed something.
« Last Edit: April 12, 2022, 10:42:31 am by paramvir »

Richard

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 41
  • Richard
    • View Profile
Re: compute cell values
« Reply #17 on: April 13, 2022, 08:01:21 am »
Hi paramvir.
I have 2 questions.

1) Regarding cell data calculation, I applied the rowTemplate that you informed me on April 8, but it did not work as I wanted.
    So, I modified it as follows and got the result I wanted, so please review it.

if(rd.cd_kind == 4){
   Object.defineProperty(rd, 'qty1', {
      enumerable: true,
      get (){
         var rd = this, ri = rd.pq_ri, pdata = grid.pageData(),
            pre_month_stock = rd['total_pre_month'],
            day = (pdata && pdata[ri-4])? pdata[ri-4].qty1: 0,
            night = (pdata && pdata[ri-3])? pdata[ri-3].qty1: 0,
            shipment = (pdata && pdata[ri-2])? pdata[ri-2].qty1: 0,
            etc = (pdata && pdata[ri-1])? pdata[ri-1].qty1: 0;
         return pre_month_stock + day + night - shipment - etc;
      }
   }),
   Object.defineProperty(rd, 'qty2', {
      enumerable: true,
      get (){
         var rd = this, ri = rd.pq_ri, pdata = grid.pageData(),
            pre_day_stock = (pdata && pdata[ri])? pdata[ri].qty1: 0,
            day = (pdata && pdata[ri-4])? pdata[ri-4].qty2: 0,
            night = (pdata && pdata[ri-3])? pdata[ri-3].qty2: 0,
            shipment = (pdata && pdata[ri-2])? pdata[ri-2].qty2: 0,
            etc = (pdata && pdata[ri-1])? pdata[ri-1].qty2: 0;
            total_this_month = pre_day_stock + day + night - shipment - etc;
         return total_this_month;

      }
   }),
   
   ....

   Object.defineProperty(rd, 'total_this_month1', { // March Results
      get (){
         return total_this_month;
      }
   })
}

2) Another question is, as in the attached image,
    if the user accesses this screen again after saving the value set by the user to show/hide the column in the DB,
    the value is retrieved from the DB and the previously set value is saved.
    I want to display it on the screen in the form.
    When the Save button is clicked, I want to save the changed value of the cell and the display/hide setting value of the column at the same time in the DB.

I would really appreciate it if you could let me how.
« Last Edit: April 13, 2022, 08:24:25 am by Richard »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: compute cell values
« Reply #18 on: April 18, 2022, 10:37:22 am »
Hi Richard

1. We can only help how to use a particular feature of pqgrid. Checking business code or logic is outside the scope of support.

2.  Columns hidden state comes under state maintenance of grid using API methods saveState and loadState.

Example: https://paramquery.com/pro/demos/grid_state

Richard

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 41
  • Richard
    • View Profile
Re: compute cell values
« Reply #19 on: April 18, 2022, 02:47:44 pm »
Hi paramvir

Referring to the screen you commented on,
it was confirmed that the setting was saved when the Save button was clicked after showing/hiding the column.
It is the state coded as below in relation to saving and loading the setting state of Show/Hide Column.

function save_column_state(){
   this.saveState();
}

{
   type: 'button',
   icon: 'ui-icon-disk',
   label: 'Save',
   cls: 'changes',
   listeners: [saveChanges,
               save_memo,
               save_column_state ],
   options: { disabled: true },
},

create: function (){
   this.loadState({ refresh: false });
},

When the user accesses the screen for the first time,
the Save button is disabled, but if a specific column is checked to show or unhide,
the Save button does not change to the enabled state.

I want to make the Save button change to enable when changing a cell.
I would really appreciate it if you could let me how to do this.
« Last Edit: April 18, 2022, 03:04:01 pm by Richard »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: compute cell values
« Reply #20 on: April 19, 2022, 12:31:00 pm »
hideCols event is triggered when a column is hidden or displayed: https://paramquery.com/pro/api#event-hideCols

So this event can be used to enable the save button.

Richard

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 41
  • Richard
    • View Profile
Re: compute cell values
« Reply #21 on: April 28, 2022, 11:26:42 am »
Hi paramvir

I would appreciate it if you could let me how to set the hideCols event to make enable the Save button.
I've tried several methods, but with no success, I'm asking you again.
« Last Edit: April 28, 2022, 11:37:31 am by Richard »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: compute cell values
« Reply #22 on: April 28, 2022, 10:11:18 pm »
Assuming you have a save button (having class 'changes' ) in the toolbar:

Code: [Select]
hideCols: function(){
var $tb = this.toolbar;
$('button.changes', $tb).button('option', { disabled: false });
},

Richard

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 41
  • Richard
    • View Profile
Re: compute cell values
« Reply #23 on: April 29, 2022, 06:28:35 am »
Hi paramvir

As a result of applying the method you gave,
there is a problem that the Save button does not change to enable
when checking a column for the first time in the Column List or unchecking it for the first time.
After the second time, the Save button is changed to enable.

Code: [Select]
hideCols: function (){
var $tb = this.toolbar;
$('button.changes', $tb).button('option', { disabled: false });
},

I'd appreciate it if you could let me know what the problem is.



paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: compute cell values
« Reply #24 on: April 29, 2022, 11:56:25 am »
Sorry about that.

Please correct

Code: [Select]
var $tb = this.toolbar;

to

Code: [Select]
var $tb = this.toolbar();