简体   繁体   中英

how to combine data from two columns in aurelia slickgrid

I have a aurelia slickgrid table with start date and end date and it is fine. Backend api response is in odata format. Now i want to make a new column called Status and status is calculated as:

<td class="col-xs-4 col-md-2">
<div>
    <div if.bind="doesLicenseActivate(lic)">
        Activates on ${lic.DateStart}
    </div>

    <div if.bind="didLicenseEnd(lic)">
        Ended on ${lic.DateEnd}
    </div>

    <div if.bind="isLicenseCurrentlyActive(lic)">
        Current License
    </div>

    <div if.bind="lic.IsCanceled">
        Cancelled on ${lic.DateEnd}
    </div>

</div>

Basically, those fucntions above such as doesLicenseActivate are bunch of Moment.js function doing some date caclulations. My column looks like:

/* Define grid Options and Columns */
private defineMembershipGrid() {
    return this.columnDefinitionsMembershipHistory = [
       { id: "DateStart", name: "Start Date", field: "DateStart", formatter: Formatters.dateEuro, sortable: true, filterable: true, minWidth: 100, },
        { id: "DateEnd", name: "End Date", field: "DateEnd", formatter: Formatters.dateEuro, sortable: true, filterable: true, minWidth: 100, },
        { id: "Duration", name: "Duration", field: "Duration", formatter:  this.DurationFormatter, sortable: true, filterable: true, minWidth: 100, },
       // make a status column here            
    ];
}

This is how it looks like: 在此处输入图像描述

And this is what i want to do, basically make a new Status column and it uses the values from first two columns (start and end date) 在此处输入图像描述

Just use a Custom Formatter, see Custom Formatter - Wiki it has the dataContext which is the item object of the entire row. You can use MomentJS to do your calculation and display "10 months" or "Current License" (I guess that last one would be a calculation and a switch/case). You can do anything you want in a Custom Formatter and it will be recalculated every time the grid re-render, if you change value of another cell it will also be recalculated. You might have problem to filter and sort though and in that case you might want to not show a filter and remove the sort.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM