dfaruque / Serenity.Extra

Name of the repo says that this is an EXTRA of http://serenity.is platform
60 stars 34 forks source link

Grid Item Picker Unexpected token when deserializing row: StartArray #77

Closed muhammedyaman closed 2 years ago

muhammedyaman commented 2 years ago

This error is given when i want to save my entity. This happens in lookupeditor when we dont have Delimited=true opiton set. Is there a solution for this? Thanks in advance. (.NET MVC Project) XRow.cs:

   [DisplayName("Offers To Be Concatenated"), LookupInclude]
        public String OffersToBeConcatenated
        {
            get { return Fields.OffersToBeConcatenated[this]; }
            set { Fields.OffersToBeConcatenated[this] = value; }
        }

XForm.cs:

[HalfWidth(UntilNext = true), _Ext.GridItemPickerEditor(typeof(TekliflerRow), Multiple = true, GridType = "CRM.SatisPazarlama.TekliflerCheckGrid", InplaceView = true)]
        public String OffersToBeConcatenated { get; set; }

XCheckGrid Constructor:

  constructor(container: JQuery) {
            super(container, { multiple: true, inplaceView: true });
            new Serenity.HeaderFiltersMixin({
                grid: this
            });
        //    this.toolbar.element.hide();
        }
dfaruque commented 2 years ago

try the following (not tested by myself)

in yourDialog.ts

        protected getSaveEntity() {
            let entity = super.getSaveEntity();

            entity.OffersToBeConcatenated = this.form.OffersToBeConcatenated.values.join(',') as any;

            return entity;
        }
muhammedyaman commented 2 years ago

I will try and let you know thank you for quick response. Eid mubarak.

muhammedyaman commented 2 years ago

This solves the saving problem but after saving the Entity I can't see the selected texts. Ids are saved successfully but texts are not visible. Screenshots below: WhatsApp Image 2022-07-08 at 14 42 51 WhatsApp Image 2022-07-08 at 14 43 11

Also is there a way to use InplaceView with multiple selection?

dfaruque commented 2 years ago

I recommend you to use another table for storing OffersToBeConcatenated instead of delimited values. Then use [LinkingSetRelation] and [GridItemPickerEditor(Multiple = true, NameFieldInThisRow = nameof(OffersToBeConcatenatedText))]

following is a rough sample

OffersToBeConcatenatedRow

        [DisplayName("Id"), Identity]
        public Int64? Id { get { return Fields.Id[this]; } set { Fields.Id[this] = value; } }

        [DisplayName("MasterId"), NotNull, ForeignKey("[MasterTable]", "Id"), LeftJoin("jMasterTable"))]
        public Int64? MasterId{ get { return Fields.MasterId[this]; } set { Fields.MasterId[this] = value; } }

        [DisplayName("OfferId"), NotNull, ForeignKey("[Offer]", "Id"), LeftJoin("jOffer"), TextualField("OfferText")]
        public Int64? OfferId{ get { return Fields.OfferId[this]; } set { Fields.OfferId[this] = value; } }

in your master Row.cs

        [DisplayName("Offers To Be Concatenated ")]
        [LinkingSetRelation(typeof(OffersToBeConcatenatedRow), nameof(OffersToBeConcatenatedRow.MasterId), nameof(OffersToBeConcatenatedRow.OfferId))]
        [GridItemPickerEditor(Multiple = true, NameFieldInThisRow = nameof(OffersToBeConcatenatedText))]
        public List<Int64> OffersToBeConcatenated{ get { return Fields.OffersToBeConcatenated [this]; } set { Fields.OffersToBeConcatenated [this] = value; } }

        [DisplayName("OffersToBeConcatenatedText "), ReadOnly(true)]
        [Expression(@"STUFF(
(SELECT ', ' + b.OfferText
FROM OffersToBeConcatenatedTable a
JOIN Offer b ON b.Id = a.OfferId
WHERE a.MasterId= T0.Id
FOR XML PATH(''))
,1,2,'')")]

        public String OffersToBeConcatenatedText { get { return Fields.OffersToBeConcatenatedText[this]; } set { Fields.OffersToBeConcatenatedText[this] = value; } }
muhammedyaman commented 2 years ago

Solid solution as always. Thank you.