Question

So im using jquery calendar plugin and Im creating a view that is more printer friendly for my organization. When the user clicks the week view and hits button that say print this view the coding below works perfect. But if they choose month view and hit print button it print entire month horizontally. Long story short how do i make this calendar crate new line on every seven count.

<table width="100%" style="border: none">
    <td style="border-style: none">
        <table style="border: none">
            @for (int index = 0; index < Model.Count - 1; index++)
            {
                var calendarDate = Model[index];
                <td style="vertical-align: top">

                    <div style="border: thin; border-style: solid; font-weight: bold">
                        @calendarDate.CalDate.ToLongDateString()
                    </div>

                    @foreach (var dayEvents in calendarDate.DateEvents)
                    {
                        <div style="border: thin; border-style: solid">
                            @dayEvents.Department<br />
                            @dayEvents.Doctor<br />
                            @dayEvents.Comments
                        </div>
                    }
                </td>
            }
        </table>
    </td>
</table>

I might be having a moment and its right in front of my eyes but im reaching out.

Was it helpful?

Solution 2

This was the approach that worked and seemed pretty clean. It works whether its in week or month view. Its pretty similar to what your approach was on the original answer. so im going to give you credit also

@{

int itemIndex = 0;
int colspan = 7;
}


<table class="printCalendarTable">
<tr style="vertical-align: top; font-weight: bold">
    @foreach (var item in Model)
    {
        if (itemIndex != 0 && itemIndex % colspan == 0)
        {
            @:</tr><tr style="vertical-align: top; font-weight: bold">
        }
        <td>@item.CalDate.ToShortDateString()
            <table>
                    @foreach (var ocEvent in item.DateEvents)
                    {
                        <tr><td>@ocEvent.Department</td></tr>
                        <tr><td>@ocEvent.Doctor</td></tr>
                        <tr><td>@ocEvent.Comments</td></tr>
                    }
            </table>
        </td>
        itemIndex++;
    }
</tr>
</table>

OTHER TIPS

You can group your model items into 7's:

var model = Enumerable.Range(0, 20).Select(x => new { Text = "item " + x });
var data = model
        .Select((value, index) => new { Index = index / 3, Item = value })
        .GroupBy(pair => pair.Index);

Then you can do this:

<table>
@foreach (var group in data)
{
    <tr>
        @foreach (var element in group)
        {
            <td>@element.Item.Text</td>
        }
        @for (int i = 0; i < 3 - group.Count(); i++)
        {
            <td>empty</td> 
        }
    </tr>
}
</table>

See Darin Dimitrov's answer in this thread: Building tables with WebMatrix

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top