jQWidgets Forums

jQuery UI Widgets Forums Grid how to set composite Key to id attribute in grid source?

This topic contains 1 reply, has 2 voices, and was last updated by  Hristo 6 years, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author

  • stanley
    Participant

    Hi,
    I have a table with composite Key.
    the composite Key are [MyNo] and [MySeq].

    var source = { datafields: [
                            { name: 'MyNo', type: 'string' },
                            { name: 'MySeq', type: 'int' },
                            { name: 'ColorNo1', type: 'string' },
                            { name: 'ColorNo2', type: 'string' },
                            { name: 'ColorNo3', type: 'string' },
                            { name: 'ColorNo4', type: 'string' },
                            { name: 'ColorNo5', type: 'string' }
                        ],
                        id: 'MyNo'
                    }

    how to set more than two field to id attribute in source?


    Hristo
    Participant

    Hello stanley,

    You could use the beforeprocessing callback in the DataAdapter’s source.
    In the same case, you could use beforeLoadComplete callback.
    Please, take a look at this source code:

    var source = {
                    localdata: data,
                    datafields: [
                      {
                          name: 'myfield'
                      },
                      {
                          name: 'firstname',
                          type: 'string'
                      }, {
                          name: 'lastname',
                          type: 'string'
                      }, {
                          name: 'productname',
                          type: 'string'
                      }, {
                          name: 'date',
                          type: 'date'
                      }, {
                          name: 'quantity',
                          type: 'number'
                      }, {
                          name: 'price',
                          type: 'number'
                      }, {
                          name: 'uniq',
                          type: 'string'
                      }
                    ],
                    datatype: "array",
                    beforeprocessing: function (data)
                    {
                        for (var i = 0; i < data.length; i++) {
                            var item = data[i];
                            data[i]["uniq"] = item.id + item.firstname + item.lastname;
                        }
    
                        return data;
                    },
                    id: 'uniq'
                };
    
                var dataAdapter = new $.jqx.dataAdapter(source, {
                    beforeLoadComplete: (records) =>
                    {
                        for (var i = 0; i < records.length; i += 1) {
                            var rec = records[i];
                            rec.myfield = i + 1;
                        }
    
                        return records;
                    }
                });

    Also, you could use the uniqueid that is automatically generated from the DataAdapter.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.