How to create an employee Schedule

13 posts, 0 answers
  1. Emmanuel
    Emmanuel avatar
    8 posts
    Member since:
    Dec 2013

    Posted 31 Dec 2013 Link to this post

    Hi,
    I downloaded one of your demos for the radscheduler. I connected it to my database and it almost does the job I need it to do. Basically I'm trying to do schedule for my employees. So I don't necessarily need the subject box instead I would like to see the names of the employees working the shift. This is the demos that i'm using http://demos.telerik.com/aspnet-ajax/scheduler/examples/resources/defaultcs.aspx
    I can have more than 1 employee working the same shift. Also I was wondering if it's possible to dynamically create the toggle button with the name of my employees coming from my database. Thank you in advance for all the help you can provide me.
  2. Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 02 Jan 2014 Link to this post

    Hi Emmanuel,

    In such scenarios we recommend using Appointment templates and Multiple resources as for example it is implemented in this on-line demo.

    Regards,
    Plamen
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Emmanuel
    Emmanuel avatar
    8 posts
    Member since:
    Dec 2013

    Posted 02 Jan 2014 Link to this post

    What if, instead of having the hours on the columns I'll have the name of the employee. Like the example image, I provided.

    Thanks
  5. Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 03 Jan 2014 Link to this post

    Hi,

    This could be achieved if you group vertically as for example it can be done in this on-line demo.

    Regards,
    Plamen
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Emmanuel
    Emmanuel avatar
    8 posts
    Member since:
    Dec 2013

    Posted 03 Jan 2014 Link to this post

    Hi,

    I tried another approach with a regular GridView. It does what I need but now I would like to recreate it using RadGrid. Can you please tell me how to make this code work in RadGrid please: 
    protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    for (var i = 1; i <= 7; i++)
                    {
                        var hDate = new HiddenField { ID = "hDate" + i, Value = string.Format("{0:yyyy-MM-dd}", _weekStart.AddDays(i - 1)) };
                        e.Row.Cells[i].Controls.Add(hDate);
                        var hEmployeeId = new HiddenField { ID = "hEmployeeId" + i, Value = ((DataRowView)e.Row.DataItem).Row["EmployeeId"].ToString() };
                        e.Row.Cells[i].Controls.Add(hEmployeeId);

                        var lstStart = TimeListBox("lstStart" + i, ((DataRowView)e.Row.DataItem).Row[GetDay(i) + "S"].ToString());
                        e.Row.Cells[i].Controls.Add(lstStart);
                        var lstEnd = TimeListBox("lstEnd" + i, ((DataRowView)e.Row.DataItem).Row[GetDay(i) + "E"].ToString());
                        e.Row.Cells[i].Controls.Add(lstEnd);
                        var lstStoreSection = StoreSectionListBox("lstStoreSection" + i, ((DataRowView)e.Row.DataItem).Row[GetDay(i) + "SS"].ToString());
                        e.Row.Cells[i].Controls.Add(lstStoreSection);
                    }

                    var lnkView = new LinkButton { ID = "lnkView", Text = "View" };
                    lnkView.Click += ViewDetails;
                    lnkView.CommandArgument = ((DataRowView)e.Row.DataItem).Row["Id"].ToString();
                    e.Row.Cells[8].Controls.Add(lnkView);
                }
            }
  7. Emmanuel
    Emmanuel avatar
    8 posts
    Member since:
    Dec 2013

    Posted 06 Jan 2014 Link to this post

    Any ideas??
  8. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 08 Jan 2014 Link to this post

    Hi Emmanuel,

    What I see from the code is that controls are being added in the rows cells dynamically. For achieving the same using RadGrid I would suggest subscribing to the OnItemCreated event. The code would look something similar to this.

    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
        {
            GridDataItem item = e.Item as GridDataItem;
            if (item != null)
            {
                for (var i = 1; i <= 7; i++)
                {
                    var hDate = //Create control
                    item.Cells[i].Controls.Add(hDate);
                    var hEmployeeId = //Create control
                    item.Cells[i].Controls.Add(hEmployeeId);
     
                    var lstStart = //Create control
                    item.Cells[i].Controls.Add(lstStart);
                    var lstEnd = //Create control
                    item.Cells[i].Controls.Add(lstEnd);
                    var lstStoreSection = //Create control
                    item.Cells[i].Controls.Add(lstStoreSection);
                }
            }
        }

    Note that if you want to populate the dynamically added controls you should do so by subscribing to the OnItemDataBound event.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            GridDataItem item = e.Item as GridDataItem;
            if (item != null)
            {
                //populate the controls
            }
        }

    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  9. Emmanuel
    Emmanuel avatar
    8 posts
    Member since:
    Dec 2013

    Posted 09 Jan 2014 Link to this post

    Thanks for your help, it worked.
    Now let say that I would like to get the value of the selected value from a dropdownlist on the clien side. My goal is to create a column Total at the end of my grid and calculate the total amount of each selected dropdownlist. 
    I found this example somewhere on the forum but it needs to be modified to fit my needs but I have no clue how to do it:
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript">
                function OnGridCreated(sender, eventArgs) {
                    var radgrid = $telerik.$(".radGrid");
                    alert("The ID of the RadGrid: " + radgrid[0].id);

                    $telerik.$('.textbox').blur(function () {
                        alert('Handler for .blur() called.');

                    });
                    $telerik.$('.ddl').blur(function () {
                        alert('DDL Changed');
                    });
                }
            </script>
        </telerik:RadScriptBlock>
  10. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 14 Jan 2014 Link to this post

    Hello Emmanuel,

    Since the last code demonstrated how to add a control in the GridDataItem I suppose that the DropDownList is placed inside the ItemTemplate of a GridTemplateColumn. If that is the case you can extract the value in the blur event handler. An exemplary scenario is shown in the code snippets below:

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server">
                <MasterTableView>
                    <Columns>
                        <telerik:GridTemplateColumn UniqueName="MyColumn">
                            <ItemTemplate>
                                <asp:DropDownList runat="server" CssClass="ddl" ID="DropDownList1">
                                    <asp:ListItem Value="1" Text="1"></asp:ListItem>
                                    <asp:ListItem Value="2" Text="2"></asp:ListItem>
                                    <asp:ListItem Value="3" Text="3"></asp:ListItem>
                                    <asp:ListItem Value="4" Text="4"></asp:ListItem>
                                    <asp:ListItem Value="5" Text="5"></asp:ListItem>
                                </asp:DropDownList>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>
                <ClientSettings>
                    <ClientEvents OnGridCreated="OnGridCreated" />
                </ClientSettings>
            </telerik:RadGrid>

    JavaScript:
    function OnGridCreated(sender, eventArgs) {
                   $telerik.$('.ddl').blur(function (e) {
                       var value = e.currentTarget.value;
                   });
               }

    If this is not the case please elaborate more on the exact scenario. Note that it would be best to show us the markup of the grid so we could get a better understanding of the setup.

    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  11. Emmanuel
    Emmanuel avatar
    8 posts
    Member since:
    Dec 2013

    Posted 14 Jan 2014 Link to this post

    It's good but it's doesn't exactly give me what I'm looking for. Could it be possible to use something else than .blur I would like the javascript trigger when I change the value in the dropdown. Also I need the script to go trough all the dropdownlist .dll to read their value. Thank you
  12. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 17 Jan 2014 Link to this post

    Hi Emmanuel,

    In order to have a better control over the client selection process I would recommend replacing the DropDownList with a RadComboBox. This will allow you to subscribe to the OnClientSelectedIndexChanged event which is fired after an item is selected. Inside the event handler logic you can traverse the grid items and obtain the values of all the combos. If we refer to the previous sample you can modify it like this.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server">
            <MasterTableView>
                <Columns>
                        <telerik:GridTemplateColumn UniqueName="MyColumn">
                            <ItemTemplate>
                                <telerik:RadComboBox runat="server" CssClass="ddl" ID="RadComboBox1" OnClientSelectedIndexChanged="selectedIndexChanged">
                                    <Items>
                                        <telerik:RadComboBoxItem Value="1" Text="1" />
                                        <telerik:RadComboBoxItem Value="2" Text="2" />
                                        <telerik:RadComboBoxItem Value="3" Text="3" />
                                        <telerik:RadComboBoxItem Value="4" Text="4" />
                                        <telerik:RadComboBoxItem Value="5" Text="5" />
                                    </Items>
                                </telerik:RadComboBox>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
            </MasterTableView>
        </telerik:RadGrid>

    JavaScript:
    function selectedIndexChanged(sender, args) {
     
                var targetedComboValue = args.get_item().get_value();
                //Extracting all the combos values
                var gridItems = $find('<%=RadGrid1.ClientID%>').get_masterTableView().get_dataItems();
                for (var i = 0; i < gridItems.length; i++) {
                    var combo = $telerik.findControl(gridItems[i].get_element(), "RadComboBox1");
                    var value = combo.get_selectedItem().get_value();
                }
            }


    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  13. Emmanuel
    Emmanuel avatar
    8 posts
    Member since:
    Dec 2013

    Posted 25 Jan 2014 in reply to Angel Petrov Link to this post

    Hi,
    Thanks for your reply. But it doesn't work. I tried the following:
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript">

                function selectedIndexChanged(sender, args) {
                    var gridItems = $find('<%=gvSchedule.ClientID%>').get_masterTableView().get_dataItems();
                    alert(gridItems.length);
                }

            </script>
        </telerik:RadScriptBlock>

    Am I missing something?






  14. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 29 Jan 2014 Link to this post

    Hello Emmanuel,

    I am experiencing difficulties understanding the problem. Are you saying that the count of the grid items is zero? Could you ensure that there was no JavaScript error present on the page prior to the execution of the illustrated code?

    Please elaborate more on the exact scenario thus facilitating us in providing an accurate answer. Additionally It would be best to show us the entire page contents so we could review the implementation.

    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017