This space is available to any ComponentArt employee to write about anything.

Browse by Tags

All Tags » ComponentArt Grid   (RSS)

  • 10
    Comments
    6410 Views

    New Grid Feature: Client-side Binding to Web Service

    Now that we got 2007.1 out the door, we can finally take some time to reflect on what we’ve done, and talk to you guys and gals out there about what’s new and notable in the release. It certainly feels good to be writing in a natural language for a change. Since one blog post would hardly suffice for discussing all the new controls and cool new features, for now I’ll focus on only one particular new feature that I think a lot of you will be excited about: client-side binding to JSON objects with Grid. One of the great features of ASP.NET AJAX is its ability to expose web services and their WebMethods to client-side code quickly and easily. Return values from WebMethods are automatically serialized to JSON and returned as such on the client. Since ComponentArt controls are fully functional on the client, there is nothing stopping them from being able to load data returned from such web service calls right on the client. Being able to programmatically populate our controls on the client is nothing new, but now, for the first time, there is a way to bind a control to a JSON data set on the client with a single line of code. This is what Grid’s new client-side load method is for. There is a sample in our new demo package which showcases this functionality ( here ) but I will explain the key points. First of all, we need a web service, with a WebMethod which will return a data set. This particular example uses a simple service we wrote called MessageService, which has a method called GetRecords that returns a List of Message objects. This list is populated by querying a table of forum posts and instantiating a rudimentary Message object for each one. After the list is built in the GetRecords method, it is simply returned. Next, we expose this web service to the client using the ASP.NET AJAX ScriptManager: <asp:ScriptManager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference path="MessageService.asmx" /> </Services> </asp:ScriptManager> At this point, we can call our GetRecords method with a single line of JS: MessageService.GetRecords(OnSucceeded); The parameter we pass in is the handle of a client-side method to call when the method returns its result: function OnSucceeded(result) { Grid1.load(result); Grid1.render(); } The call to Grid’s load method with the returned JSON data set is all that is needed to bind the Grid with the new data on the client. The call to render then simply redraws the Grid. I know, that’s pretty cool, right? Note that in order for the Grid to know which properties of those JSON objects to load for the various columns, its column DataField definitions must match the property names of the objects, in this case the Message object. Note also that such objects need not necessarily be loaded from a web service. Any array of client-side objects can be loaded using the load method. Hopefully we’ll get a chance to implement similar functionality for some other controls fairly soon, like TreeView, ComboBox, Menu, and others. Bye for now! Share this post: email it! | bookmark it! | digg it! | reddit!

    Posted by: Milos
    Posted: Wednesday, May 02, 2007 12:36 PM
    Filed under: , , , ,
    10 Comments



  • New Grid Feature: Item Drag and Drop

    As of Web.UI 2006.2, Grid has a useful new feature: item drag and drop. For some time, many of you have been asking for such a feature, for many different reasons. Some wanted to be able to drag Grid items to and from a TreeView, others wanted to be able to re-order them, or to drag them to other external containers. Since we don't yet have an example which takes advantage of this new feature, I thought I'd provide a brief overview of how it's used: 1. Set ItemDraggingEnabled to true This enables dragging functionality - you can now drag a Grid item (row). By default, the item you drag will look like a copy of the Grid item, but you can use the ItemDraggingClientTemplateId and ItemDraggingCssClass properties to modify the appearance of the item as it is dragged. 2. Set the ExternalDropTargets property This property is of type string and should be set to a comma-delimited list of potential drop target IDs. These can be ComponentArt control IDs or DOM element IDs. If you wanted to be able to drop Grid items to TreeView with ID "TreeView1" and a DIV with ID "dropTargetDiv", you would set ExternalDropTargets to "TreeView1,dropTargetDiv". 3. Set the ItemExternalDrop client event handler in the ClientEvents block For instance: <ComponentArt:Grid runat="server" id="Grid1" ... > ... <ClientEvents> <ItemExternalDrop EventHandler="Grid1_onItemExternalDrop" /> </ClientEvents> </ComponentArt:Grid> 4. Define the handler For instance: function Grid1_onItemExternalDrop(sender, eventArgs) { var draggedItem = eventArgs.get_item(); var targetControl = eventArgs.get_targetControl(); var target = eventArgs.get_target(); // perform logic } In this example, draggedItem would be the GridItem that was dragged. The variable targetControl would be set to the target client control (if the target is one), like a TreeView or a Grid. The target would be either a DOM element, in the case that the drop target was a simple DOM element, or a more abstract object, such as a TreeViewNode, if the target was a TreeView. You can then use the Web.UI client-side API to perform any custom logic you require. While seemingly complicated, we feel that this kind of approach is general enough to cover all desired scenarios, yet simple enough to result in clean and readable code in most real-world applications. As always, we love to hear feedback from you, which help us to evolve this feature in useful ways. Have fun! Share this post: email it! | bookmark it! | digg it! | reddit!

    Posted by: Milos
    Posted: Wednesday, November 22, 2006 9:44 AM
    Filed under: , ,
    18 Comments




Blogs On This Site
Thoughts on web user interfaces and component development.
Ramblings of a web control developer.
Web.UI news and more
Next weeks guest: A dog and a baby dog!
I'm in your base, killing your dudes.
Absurdity is it's own message.
Musings of an ex Java developer
im in ur page, hackin ur codez
ComponentArt in the Community
... and the program ran happily ever after.

This Blog