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

foreign key field in non editing grid shows summary fields from main table

Hello,
i have an normal non edit grid with a foreign key filed.
The foreign key field is of type summary.

When i start the app the grid shows the summary fields of the main table. 

pls see this video


render function code is default with some flags like sorting:
 
myapp.BrowseFirmen.Firmen_render = function (element, contentItem)
{
    // Write code here.
    var itemTemplate = $("<div></div>").attr('id', 'Firmen')

    // Append the div element to screen 
    itemTemplate.appendTo($(element));

    contentItem.value.oncollectionchange = function ()
    {

        if (itemTemplate.hasClass('e-grid'))
        {
            itemTemplate.ejGrid('destroy');
        }
        var first = contentItem.children[0], fieldname = [];
        for (i = 0; i < first.children.length; i++)
        {
            fieldname[i] = { field: first.children[i].valueModel.name };
        }

        //Rendering the Grid Control
        itemTemplate.ejGrid(
            {
                dataSource: contentItem.value.data,
                allowPaging: true,
                allowSorting: true,
                allowMultiSorting: true,
                allowResizing: true,
                columns: fieldname
            });
    }
}

please help to solve this problem...

Kind Regards
Thomas

3 Replies

RU Ragavee U S Syncfusion Team August 4, 2015 11:13 AM UTC

Hi Thomas,

Thanks for your interest in Syncfusion products.

We have analyzed the reported query and have viewed the video that you have shared with us.

We suspect that by foreign key field, you mean complex type field such that the field Mandant has two properties Name and aktiv. Hence the type of the column in the lightswitch screen page(BrowseFirmen.lsml) is displayed as summary.

When binding a complex type field to the grid, we need to specify the field name as in the below code snippet.

itemTemplate.ejGrid(

            {

                dataSource: dataManager,               

                allowSorting: true,

                allowPaging: true,               

                columns: [

                        { field: "ID", headerText: "ID", isPrimaryKey: true, textAlign: ej.TextAlign.Right, width: 90 },

                        { field: "Company", headerText: 'Company', width: 90 },

                        { field: "Address", headerText: 'Address', width: 90 },

                        { field: "TaxNumber", headerText: 'Taxnumber', width: 90 },

                        { field: "Website", headerText: 'Website', width: 150 },

                        { field: "PostalNumber.PostalNr", headerText: 'Postalnumber', width: 90 },

                        { field: "City.Code", headerText: 'City', width: 90 }

                ],

                actionComplete: function (args) {

                    if (args.requestType == "save")

                        myapp.applyChanges();

                },

            });
    }

For which the dataSource will be in the below format

{  ID: 10248,

   Company: "VINET",

   Address: 5,

   Website: "Vins et alcools Chevalier",

   TaxNumber: 32.38,

   PostalNumber: { PostalNr: "51100" },

  City: {Town:"Reims", Code:"042"}}
        }


For your convenience, we have created a sample with complex binding and the same can be downloaded from the below location.

Sample Link: http://www.syncfusion.com/downloads/support/forum/119805/ze/LightSwitchDropdownData1835034065

Please get back to us if you need any further assistance.

Regards
Ragavee U S


TS Thomas Steschulat August 7, 2015 09:39 AM UTC

Hello,
i am not sure if i told correctly what i wanted to do.

I used the Grid  Template Screen with the table "Firma". In the table "Firma" i have an FK or Relationship to "Mandant".
The resultig grid in the screen has a summary Filed for "Mandant". Mandant has the Field "Name" (String) as summary field in data sources table definition.

I start the application and EJ Grid shows in the column "Mandant" the values of the Field "Name" from the table "Firma".

That seems to be a bug. 
i think that the problem is that part of the generated code:

        var first = contentItem.children[0], fieldname = [];
        for (i = 0; i < first.children.length; i++)
        {
            fieldname[i] = { field: first.children[i].valueModel.name };
        }
        //Rendering the Grid Control
        itemTemplate.ejGrid(
            {
                dataSource: contentItem.value.data,
                allowPaging: true,
                allowSorting: true,
                allowMultiSorting: true,
                allowResizing: true,
                columns: fieldname
            });

That works fine and is much easier as having all the single fields in the itemtemplate.ejgrid
But it doesnt work for a relationship with two tabels that have the same field name.
The tablename must be added somehow before the fieldname. (Firma.Name, Mandant.Name" or something else

I hope i have explained that well :-)

Kind regards
Thomas


RU Ragavee U S Syncfusion Team August 10, 2015 10:51 AM UTC

Hi Thomas,

We have analyzed your query.

Based on your requirement, we have modified the code to append the table name with the fieldName thus handling the issue reported. Please refer the below code snippet.

for (i = 0; i < first.children.length; i++) {

            if (ej.isNullOrUndefined(first.children[i].valueModel.elementType)) //checking if the field is of complex type

                fieldname[i] = { field: first.children[i].valueModel.name, width: 100 };

            else {

                fieldname[i] = { field: first.children[i].valueModel.name + "." + first.children[i].valueModel.elementType[":@SummaryProperty"].property.name, width: 100 };//merge the table name with the summary property of the table and assign it as fieldName

            }
        }


In the above snippet, we have checked if the field is complex and thus obtained the summary property of the field and appended it with the table name. The above code snippet will work dynamically for all control types for the corresponding field.

For your convenience, we have modified our previously updated sample with the above solution and the sample can be downloaded from the below location.

Sample Link: http://www.syncfusion.com/downloads/support/forum/119805/ze/LightSwitchDropdownData_Modified-961726019

Please get back to us if you need any further assistance.

Regards
Ragavee U S

Loader.
Up arrow icon