We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

ejGrid -> column referencing an array (multiple values)

I have an ejGrid with a column that is referencing a foreign data source using multiple values, but it is only displaying correctly for single-value arrays.  Is there a way to display multiple values?

example: 

var tableData = [
{
someGUID: '3eaf4e59-a462-417c-94b9-46d321b155e7',
someProperty: 'Default',
someIntID: 2,
arrayOfIDs: [2]
},
{
someGUID: '3eaf4e59-a462-417c-94b9-46d321b155e7',
someProperty: 'Default',
someIntID: 2,
arrayOfIDs: [2, 4]
}
];

var staticMappedData = [
{ID: 0, value: "a"},
{ID: 1, value: "b"},
{ID: 2, value: "c"},
{ID: 3, value: "d"}
];

$(document).ready(function () {
$("#grid").ejGrid({
dataSource: tableData,
columns: [
{ field: "someGUID" },
{ field: "someProperty" },
{
field: "arrayOfIDs",
foreignKeyField: "ID",
foreignKeyValue: "value",
dataSource: staticMappedData
}
]
});
});

Thanks.

-dave

Attachment: demo_fc46f206.zip

1 Reply

MS Madhu Sudhanan P Syncfusion Team February 18, 2015 12:18 PM UTC

Hi Dave,

Thanks for using Syncfusion products.

We have analyzed the attached sample and we would like to let you that it is not feasible to bind array value in columns using foreign key. But we can achieve your requirement with the column template feature of the grid.

Please refer the below code snippet.

//Helper function

function arrayMatch(){

       var fullData = this.data.arrayOfIDs, res = [];

             

       staticMappedData.filter(function(data){

              if($.inArray(data.ID,fullData) != -1){

                     res.push(data.value);

              }

       });

               

       return res.join(",");

}

$(document).ready(function () {

             

        //Registering helper

              $.views.helpers({ DisplayArray: arrayMatch});

             

                     $("#grid").ejGrid({

                           dataSource: tableData,

                           columns: [

                                  { field: "someGUID" },

                                  { field: "someProperty" },

                                  {

                                      field: "arrayOfIDs",

                                      //Defining the template of the column

                                      template: "{{:~DisplayArray()}}"

                                  }

                           ]

                     });

              });

 

For you convenience, we have modified the attached sample with the above code snippet and the same can be downloaded from the below location.

Sample Location: http://www.syncfusion.com/downloads/support/directtrac/118264/arraybinding1771230755.zip

For your kind information, we cannot perform grid actions such as sorting, filtering, grouping etc on template column.

Please let us know if you have any queries.

Regards,

Madhu Sudhanan. P



Loader.
Up arrow icon