Server side editor, add custom field

Server side editor, add custom field

eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

because i cant make left join to table with composite keys, how can i bring extra data for each row from this table and send it in the editor response?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,438Questions: 1Answers: 10,049 Site admin

    You could use a VIEW for the composite key join if you wanted.

    I'm not clear on the point about getting extra data though? If it's coming from the database, then you'd just use another Field like all the other columns. If it's a calculated value then use columns.render to compute it on the client-side.

    Allan

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    its come form the database, but from different table,
    and i cant use join!
    so my question if i can add a field and then get the value by sql query?

  • allanallan Posts: 61,438Questions: 1Answers: 10,049 Site admin

    I don't get it - why can't you use a join? You'd need a SELECT statement for every single row in the table - if you had only 1000 rows in the table that's 1001 SELECT queries just to display it!

    That is not something that Editor facilities I'm afraid.

    Allan

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    hey Allan, maybe you didn't understand me and i didn't understand you
    this is my code for get data from trip table

    [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
            public ActionResult GetDataTrip(Enums.JsonSortType type, int id)
            {
                var settings = Properties.Settings.Default;
                var formData = HttpContext.ApplicationInstance.Context.Request;
    
                using (var db = new DataTables.Database(settings.DbType, settings.DbConnection))
                {
                    var editor = new Editor(db, "Trip", "Trip_Id");
                    if (type == PegasusOperation.Common.Classes.Enums.JsonSortType.TripByTour)
                    {
                        editor.Where("Trip.Trip_Id", id);
                    }
                    editor.Model<Model.Trip>("Trip")
                        .Field(new Field("Trip.Trip_Id")
                        .Validator(Validation.Numeric())
                    )
                        .Field(new Field("Trip.Trip_Name").Xss(false)
                        .Validator(Validation.Unique(new ValidationOpts
                        {
                            Message = "שם המסלול קיים, השם חייב להיות יחודי"
                        }))
                        .Validator(Validation.MaxLen(50))
                        .Validator(Validation.NotEmpty(new ValidationOpts
                        {
                            Message = "חובה לתת שם למסלול הטיול"
                        }))
                    )
                        .Field(new Field("Trip.Trip_DaysNum").Xss(false)
                        .Options(() => getDayList()
                        )
                        .Validator(Validation.Numeric())
    
                    )
                    .Field(new Field("Trip.Requires_Flights", typeof(bool))
                    )
                    .MJoin(new MJoin("Countries")
                    .Link("Trip.Trip_Id", "Trip_Countries.Trip_Id")
                    .Link("Countries.Country_Id", "Trip_Countries.Country_Id")
                    .Model<Model.Countries>()
                    .Order("Countries.Country_Id")
                    .Field(new Field("Country_Id")
                        .Options("Countries", "Country_Id", "Country_Name")
                    ));
                    editor.MJoin(new MJoin("DayTrip")
                   .Link("Trip.Trip_Id", "Trip_DayTrip.Trip_Id")
                   .Link("DayTrip.DayTrip_Id", "Trip_DayTrip.DayTrip_Id")
                   .Model<Model.DayTripVM>()
                   .Order("DayTrip.DayTrip_Id")
                   .Field(new Field("DayTrip_Id")
                       .Options("DayTrip", "DayTrip_Id", "TripName")
                   ));
                    editor.Debug(true);
    
                    //// Pre functions
                    editor.PreEdit += (sender, e) => prev_Values = getRawData(e.Id, db);
                    editor.PreRemove += (sender, e) => prev_Values = getRawData(e.Id, db);
    
    
                    // Post functions
                    editor.PostCreate += (sender, e) =>
                    {
                        var values = getRawData(e.Id, db);
                        Functions._LogChange2(db, "מסלולי טיול", "create", e.Id, values, prev_Values);
                    };
                    editor.PostEdit += (sender, e) => 
                    {
                        var values = getRawData(e.Id, db);
                        Functions._LogChange2(db, "מסלולי טיול", "edit", e.Id, values, prev_Values);
                    };
                    editor.PostRemove += (sender, e) => Functions._LogChange2(db, "מסלולי טיול", "remove", e.Id, e.Values, prev_Values);
    
                    editor.Process(formData.Unvalidated.Form);
                    DtResponse data = editor.Data();
                    return Json(data, JsonRequestBehavior.AllowGet);
    
                    }
                }
    

    now i want to get from Trip_dayTrip table(photo attached) the count of days for each trip and sent it to client,beacuse i cant used left join to this table how can i get the data? (with entity framework it easy, just trip.Trip_dayTrip.count)

  • allanallan Posts: 61,438Questions: 1Answers: 10,049 Site admin
    Answer ✓

    Thank you - the image clears things up a lot!

    With the .NET Editor libraries you'd use Mjoin for this. That will perform a n-m join and you can simply use the .length of the resulting array to display the count. The many file upload example uses the length for display of how many images belong to a row.

    Allan

This discussion has been closed.