Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

jTable - Display item from Foreign Key table #3331


User avatar
0
20summers created

Hi,

I have the following foreign key in my model:

public virtual PlanStatus Status { get; set; }
        public int? StatusId { get; set; }

in jTable I can display the StatusId

statusId: {
                title: app.localize("Status"),
                width: "30px",
                display: function (data) {
                    if (data.record.statusId) {
                        console.log(data.record);
                         return data.record.statusId;
                    }

                }
            },

in the PlanStatus model I have a field Status that I want displayed in the jTable.

How do I display it?


4 Answer(s)
  • User Avatar
    0
    20summers created

    WIll I have to do something like below or is their an easier way?

    private IQueryable<AuditLogAndUser> CreateAuditLogAndUsersQuery(GetAuditLogsInput input)
            {
                var query = from auditLog in _auditLogRepository.GetAll()
                    join user in _userRepository.GetAll() on auditLog.UserId equals user.Id into userJoin
                    from joinedUser in userJoin.DefaultIfEmpty()
                    where auditLog.ExecutionTime >= input.StartDate && auditLog.ExecutionTime <= input.EndDate
                    select new AuditLogAndUser {AuditLog = auditLog, User = joinedUser};
    
                query = query
                    .WhereIf(!input.UserName.IsNullOrWhiteSpace(), item => item.User.UserName.Contains(input.UserName))
                    .WhereIf(!input.ServiceName.IsNullOrWhiteSpace(), item => item.AuditLog.ServiceName.Contains(input.ServiceName))
                    .WhereIf(!input.MethodName.IsNullOrWhiteSpace(), item => item.AuditLog.MethodName.Contains(input.MethodName))
                    .WhereIf(!input.BrowserInfo.IsNullOrWhiteSpace(), item => item.AuditLog.BrowserInfo.Contains(input.BrowserInfo))
                    .WhereIf(input.MinExecutionDuration.HasValue && input.MinExecutionDuration > 0, item => item.AuditLog.ExecutionDuration >= input.MinExecutionDuration.Value)
                    .WhereIf(input.MaxExecutionDuration.HasValue && input.MaxExecutionDuration < int.MaxValue, item => item.AuditLog.ExecutionDuration <= input.MaxExecutionDuration.Value)
                    .WhereIf(input.HasException == true, item => item.AuditLog.Exception != null && item.AuditLog.Exception != "")
                    .WhereIf(input.HasException == false, item => item.AuditLog.Exception == null || item.AuditLog.Exception == "");
                return query;
            }
    
  • User Avatar
    0
    exlnt created

    In my table class I have setup a FK using the code below.

    [Required]
            [ForeignKey("ListValuesCF")]
            public int ContributionFrequency { get; set; }
            public virtual ListValues ListValuesCF { get; set; }
    

    In my ResidentFundingListDto I have the following two properties. public int ContributionFrequency { get; set; } public string ContributionFrequencyName { get; set; } The second one holds the "text" value for the frequency. This is what I display on my JTable grid.

    Then I used the code shown below to display the "text" value on my JTable grid.

    public async Task<PagedResultDto<ResidentFundingListDto>> GetResidentFundingSources(GetResidentFundingInput input)
            {
                   var query = from rf in _residentFundingRepository.GetAll()
                                select new ResidentFundingListDto
                                {
                                    ActiveYesNo = rf.ActiveYesNo,
                                    ContributionAmount = rf.ContributionAmount,
                                    ContributionFrequency = rf.ContributionFrequency,
                                    ContributionFrequencyName = rf.ListValuesCF.ListText, //This is a join to table named ListValues 
                                    CreationTime = rf.CreationTime,
                                    Id = rf.Id
                                };
                    query = query.WhereIf(!input.Filter.IsNullOrWhiteSpace(), R => R.ResidentName.Contains(input.Filter));
                    var resultCount = await query.CountAsync();
                    var results = await query.OrderBy(input.Sorting).PageBy(input).ToListAsync();
                    return new PagedResultDto<ResidentFundingListDto>(resultCount, results);
                }
            }
    
  • User Avatar
    0
    20summers created

    Brilliant - thanks so much!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks a lot @exlnt :)