Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - iamdileep

Pages: [1]
1
Hi,

1)If configurable set to true, on grid refresh the nested json fields are repeating in column model.
2)Set(val) is not working properly, since userData is an indexed array (Example., userData:['abcd']) on edit we are getting old data only.

Following is the jsfiddle link contains the source code for remote data.
https://jsfiddle.net/sart_tech/60voedjq/89/

2
Thanks for the solution. I am able to render the data as I requested.
But I have some concerns,
1)When grid refresh is triggered, it's throwing an error for saying that "Cannot redefine property: father_name" which does not allowing to reassign the template row for nested json data.
2)On edit it's sending old data only not the updated one.
3)How to send the data as nested json (as like as input given) on edit & save?

3
Here is my code for remote dataModel

var rowTemplate = {};

        var dataModel= {
          dataType: "JSON",
          location: "remote",
          paging: "remote",
          sorting: "remote",
          recIndx: "id",
          sortIndx: "id",
          sortDir: "down",
          colIndx:"id",
          url: "get_grid_data?id=1",
          getData: function (response) {
              if(response.status=='success'){
                var grid_data=response.datas;
                var jsonobj = jQuery.parseJSON(grid_data[0].input_json);
                jsonobj.forEach(function(item, indx) {
                    colModel.push({
                      dataIndx: item.name,
                      title: item.label
                    });
                    (function(_indx) {
                      Object.defineProperty(rowTemplate, item.name, {
                        enumerable: true,
                        // configurable:true,
                        get() {
                          return this.jsonobj[_indx].userData;
                        },
                        set(val) {
                          this.jsonobj[_indx].userData = val;
                        }
                      })
                    })(indx);
                  });
                return {curPage: response.page_number, totalRecords: response.total_rows, data: grid_data };
              }else{
                swal(response.message);
              }
          }
        };

4
I have tried your example, its working fine.
But how to do this in case of remote dataModel?

5
I wanted to display the nested json as columns with other common fields.
In my previous example, "label" key has to be the column name and "userData" key will be the value in the grid.

Example 2:
{
    "id": "1",
    "name": "abcd",
    "email": "[email protected]",
    "phone":"1234567890",
    "custom_fields": [
        {
            "type":"text",
            "name":"father_name",
            "label":"Father Name",
            "userData":"XYZ"
        },
        {
            "type":"text",
            "name":"mother_name",
            "label":"Mother Name",
            "userData":"HIJK"
        },
        {
            "type":"text",
            "name":"graduation",
            "label":"Graduation",
            "userData":"BE"
        },
        {
            "type":"text",
            "name":"college_name",
            "label":"College Name",
            "userData":"Bangalore University"
        }
    ]
},
{
    "id": "2",
    "name": "xyz",
    "email": "[email protected]",
    "phone":"1234567890",
    "custom_fields": [
        {
            "type":"text",
            "name":"father_name",
            "label":"Father Name",
            "userData":"ABCD"
        },
        {
            "type":"text",
            "name":"mother_name",
            "label":"Mother Name",
            "userData":"PQRS"
        },
        {
            "type":"text",
            "name":"graduation",
            "label":"Graduation",
            "userData":"MSC"
        },
        {
            "type":"text",
            "name":"college_name",
            "label":"College Name",
            "userData":"Mysore University"
        }
    ]
}

Grid to be displayed:

6
Hi,

In the following URL, you have explained the nested json datamodel.
https://paramquery.com/pro/demos/json_nested

But in my case, I have a json data with the dynamic key, value pair. So I cannot predefine the column as shown in your example.

Json example,
{
    "id": "1",
    "name": "abcd",
    "email": "[email protected]",
    "phone":"1234567890",
    "custom_fields": [
        {
            "type":"text",
            "required":true,
            "label":"address",
            "className":"form-control",
            "userData":"MG Road"
        },
        {
            "type":"text",
            "required":true,
            "label":"city",
            "className":"form-control",
            "userData":"Bangalore"
        },
        {
            "type":"text",
            "required":true,
            "label":"pincode",
            "className":"form-control",
            "userData":"560042"
        }
    ]
}

custom_fields column may have different kind of objects, so how to handle the dynamic json data?

Pages: [1]