This is a migrated thread and some comments may be shown as answers.

Adding attributes to a resource

4 Answers 194 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Datamex
Top achievements
Rank 2
Datamex asked on 20 Nov 2009, 01:58 PM
Hi,

I am trying to send extra information about a resource with the resource in the webservice call "GetResources". I need the information for colouring depending on certain properties of the resource.

To do this, I add the attributes to the resource in the webservice. The resources are bound serverside, the rest of the information for the scheduler is bound clientside. The information colours cells based on the date and resource (to indicate when a resource is working or not), so I need to access the information clientside, i.e. in javascript. But when I get the resource from a timeslot, or all resources of the scheduler in javascript, none of them have any attributes, while they should have at least one (I call resource.Attributes.Add("test", "testing"); on every resource in my webservice).

Am I missing something, or is it impossible to get these attributes on the clientside? I know the same trick works with appointments. I add loads of different attributes to them serverside (in the webservice method) and I can access them without any problems clientside.

4 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 26 Nov 2009, 04:27 PM
Hello,

I've just tested this and the resource attributes seem to be available on the client. I've tried setting the attributes in both the provider and the web service:

[WebMethod(EnableSession = true)]
public IEnumerable<ResourceData> GetResources(SchedulerInfo schedulerInfo)
{
    IEnumerable<ResourceData> resources = Controller.GetResources(schedulerInfo);
    foreach (ResourceData resData in resources)
    {
        resData.Attributes["testKey"] = "testData";
    }
 
    return resources;
}

I could then access them on the client.

var scheduler = $find("RadScheduler1");
var td = $telerik.$(".rsTopWrap .rsContentTable tr:nth-child(3) td:nth-child(2)")[0];
 
scheduler.get_activeModel().getTimeSlotFromDomElement().get_resource().get_attributes().getAttribute("testKey")
 
scheduler.get_resources().getResource(0).get_attributes().getAttribute("testKey")

Maybe I'm missing something here. What approach do you use to access the attributes?

Kind regards,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Datamex
Top achievements
Rank 2
answered on 01 Dec 2009, 08:45 AM
Hmmm,

I will try setting Attributes using your approach of item.Attributes["Key"] = "Value"; I wonder why I didn't think of trying it that way. I have been using item.Attributes.Add("Key", "Value");

I'll let you know if this solves the problem. Thanks for the reply.

[edit]
I forgot to mention that I access the attributes in this way:
scheduler.get_resources().getResource(0).get_attributes().getAttribute("Key") 
[/edit]
0
Datamex
Top achievements
Rank 2
answered on 01 Dec 2009, 11:32 AM
I have in my page:
<telerik:RadScheduler ID="RadScheduler" runat="server" Height="100%" SelectedView="TimeLineView" 
            StartInsertingInAdvancedForm="True" OverflowBehavior="Expand" HoursPanelTimeFormat="htt" 
            Culture="nl-NL" DisplayRecurrenceActionDialogOnMove="True" GroupBy="Employee" AllowInsert="True" DisplayDeleteConfirmation="false"  
            StartEditingInAdvancedForm="true" OnClientAppointmentEditing="ClientCancelEvent" OnClientAppointmentDeleting="ClientDeleteEvent"   
            OnClientAppointmentDoubleClick="ClientAppointmentClick" OnClientAppointmentCreated="TimeSlotCreated" 
            OnResourcesPopulating="Resource_Populating" OnClientAppointmentInserting="OnClientAppointmentInserting" 
            OnClientAppointmentResizeEnd="AppointmentResized" OnClientAppointmentMoveEnd="AppointmentMoved" 
            OnClientAppointmentsPopulating="OnClientAppointmentsPopulating" OnClientAppointmentContextMenu="appointmentContextMenuCreating" 
            Width="100%" OnClientNavigationCommand="NavigationCommand" WorkDayStartTime="08:30" WorkDayEndTime="17:30" 
            OnClientAppointmentsPopulated="OnClientAppointmentsPopulated" DataStartField="Start" DayStartTime="07:00" 
            DayEndTime="19:00" ShowAllDayRow="true"  ShowHoursColumn="true" ShowFullTime="true"
            <Localization AdvancedAllDayEvent="All day" /> 
            <WebServiceSettings Path="~/WebServices/SchedulerWebService.asmx" ResourcePopulationMode="ServerSide" /> 
            <AdvancedForm DateFormat="dd-MM-yyyy" TimeFormat="HH:mm" Modal="true" /> 
            <TimelineView GroupingDirection="Vertical" SlotDuration="0:30:0.0" HeaderDateFormat="dddd dd MMMM yyyy" TimeLabelSpan="2" 
              GroupBy="Employee" NumberOfSlots="24" ColumnHeaderDateFormat="HH:mm" StartTime="07:00" ShowInsertArea="false" />
            <WeekView UserSelectable="false" /> 
            <DayView HeaderDateFormat="dddd dd MMMM yyyy" /> 
            <MonthView UserSelectable="false" /> 
            <AppointmentContextMenuSettings EnableDefault="true" />     
          </telerik:RadScheduler> 

In my webservice I have:
[WebMethod] 
    public IEnumerable<ResourceData> GetResources(CustomSchedulerInfo schedulerInfo) 
    { 
      IEnumerable<ResourceData> resources = Controller.GetResources(schedulerInfo); 
      foreach (ResourceData resData in resources) 
      { 
        resData.Attributes["test"] = "testData"; 
      } 
 
      return resources; 
    }
When I put a breakline on the return statement, I can see that all the resources have the attribut set.

In my page again I have as handler for the OnClientAppointmentsPopulating event:
function OnClientAppointmentsPopulated(sender, args) { 
      var scheduler = $find('<%=RadScheduler.ClientID %>'); 
      var allResources = scheduler.get_resources(); 
      var test = scheduler.get_resources().getResource(1).get_attributes().getAttribute("test"); 
      alert(test); 
    }

I use Firebug to debug the javascript, when I put a breakline on the alert statement and take a look at the variable "allResources", I can see all my resources, but none of them have any attributes. Also, test is undefined and the alert shows "undefined" in an alert box.

Am I missing anything?
0
T. Tsonev
Telerik team
answered on 04 Dec 2009, 02:35 PM
Hi,

Thank you for the detailed information.  I was finally able to reproduce the issue. It's occurring only with the 3.5 version of the assembly and I was testing with the 2.0 version until now.

We're using the DataContractJsonSerializer in this build and it can't handle the attributes dictionary that the ASP.NET 2.0 (non-WCF) web service returns.

Unfortunately, the fix is not that simple. We'll be working on it, but for the moment my recommendation is that you convert your web service to WCF. We have an example here:
http://demos.telerik.com/aspnet-ajax/scheduler/examples/wcf/defaultcs.aspx

I'm also attaching you a sample site with WCF service.

I hope this helps.

Greetings,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Scheduler
Asked by
Datamex
Top achievements
Rank 2
Answers by
T. Tsonev
Telerik team
Datamex
Top achievements
Rank 2
Share this question
or