Author Topic: Detail grid with edit buttons  (Read 7781 times)

forwheeler

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 26
    • View Profile
Detail grid with edit buttons
« on: January 01, 2014, 03:13:45 am »
What is the best way to implement this? Should I copy the edit code from my main grid such as the button bindings to the detail model?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Detail grid with edit buttons
« Reply #1 on: January 01, 2014, 11:47:48 am »
Detail / Nested grid supports the functionality & features as the main grid. So the code from main grid can be copied to the detail grid.

The options should not be shared between the grids. If the child grid has options identical to the parent grid, they should be redefined or deep cloned before using in child grid.

 


forwheeler

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Detail grid with edit buttons
« Reply #2 on: January 06, 2014, 07:11:45 pm »
When you say the options should not be shared are you saying I should copy the button binding code to the detail grid and rename the css classes? I don't understand the detail model and how it relates to the detail grid.
An example would be very helpful since I am not a javascript expert.
« Last Edit: January 06, 2014, 08:09:49 pm by forwheeler »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Detail grid with edit buttons
« Reply #3 on: January 06, 2014, 08:50:08 pm »
By options I mean the javascript options passed on to pqGrid constructor pqGrid() defined in API
http://paramquery.com/pro/api

API documentation for detailModel option is provided here http://paramquery.com/pro/api#option-detailModel

There are two examples which would help you to get started with detail view

Basic Example:
http://paramquery.com/pro/demos/nesting

Another Example:
http://paramquery.com/pro/demos/detail

« Last Edit: January 07, 2014, 08:00:35 am by paramquery »

forwheeler

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Detail grid with edit buttons
« Reply #4 on: January 07, 2014, 11:53:44 pm »
I copied the button binding to the detail grid and modified the class names to make sure I am refereeing to the detail buttons.
I copied the function for add, edit, update and delete and renamed them to editRowDetail for example. I now need to refer to the detail grid so I can set it to edit mode etc.
In this function in the demo you have

Code: [Select]

  function editRowDetail(rowIndx) {
               $grid.pqGrid("addClass", { rowIndx: rowIndx, cls: 'pq-row-edit' });
                $grid.pqGrid("editFirstCellInRow", { rowIndx: rowIndx });
How do I refer to the detail grid here instead of the main grid.

Also in the demo you have
Code: [Select]
            init: function (ui) {
                var rowData = ui.rowData,
                    id = rowData["ID"];
 
                //make a deep copy of gridDetailModel
                var objCopy = $.extend(true, {}, gridDetail);
 
                objCopy.dataModel.url = "/" + id;
                objCopy.dataModel.error = function () {
                    $gridMain.pqGrid("rowInvalidate", {rowData:rowData});
                };
                var $grid = $("<div></div>").pqGrid(objCopy);                   
                return $grid;
            }
Later on in my code I reference the main grid like this

Code: [Select]
            var $grid = $("#jsongrid").pqGrid(gridMain);

I tried to refer to the detail grid using objCopy but that doesn't work.
« Last Edit: January 07, 2014, 11:55:22 pm by forwheeler »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Detail grid with edit buttons
« Reply #5 on: January 08, 2014, 01:35:01 pm »
You have raised a very good point. Let me rephrase/summarize your question:

Quote
How do you take reference to detail grids in callbacks/ events without saving their reference in global variables?

There is a simple solution to this use case:

'this' keyword in the events/callbacks provide reference to widget DOM node (pqgrid in our case) which can be used to get reference to the relevant / affected grid.

Code: [Select]
var $grid = $(this);

As an example, I've made changes in the editing demo so that the reference is taken from 'this' keyword rather than relying on global variable.

http://paramquery.com/pro/demos/editing








« Last Edit: January 08, 2014, 01:38:59 pm by paramquery »

forwheeler

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Detail grid with edit buttons
« Reply #6 on: January 08, 2014, 10:21:53 pm »
Ok at helps. I have most of it working now.
I get an error, Object doesn't support property or method 'pqGrid' here as your new example shows.
'this' doesn't know about pqGrid.

Code: [Select]
    var ajaxObj = {
                dataType: "JSON",
                beforeSend: function () {
                    this.pqGrid("showLoading");
                },
                complete: function () {
                    this.pqGrid("hideLoading");
                },
                error: function () {
                    this.pqGrid("rollback");
                }
            };

Also in the nested grid, 'isDirty' is always false. I have track set to true so is there any other setting I need to make?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Detail grid with edit buttons
« Reply #7 on: January 08, 2014, 10:46:18 pm »
In the demo on line 53 context: $grid provides 'this' context to ajax object. Simlarly on line 125.

Quote
Also in the nested grid, 'isDirty' is always false. I have track set to true so is there any other setting I need to make?

Have you provided recIndx in the dataModel?
http://paramquery.com/pro/api#option-dataModel-recIndx


forwheeler

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Detail grid with edit buttons
« Reply #8 on: January 09, 2014, 01:08:39 am »
You provided the correct solution on both issues. Thanks.