|
11.02.2012, 07:16 | #1 |
Участник
|
Solutions Monkey: Async call to display method from the EP via a web service for delay loading
Источник: http://blogs.msdn.com/b/solutions/ar...y-loading.aspx
============== Dave Parslow from the EP dev team came out with this sample to demonstrates how to do a call to display method from the EP via a web service and have the result show up in the UI such as the grid async. Sample xpo is attached with this blog post. SampleService.asmx This is a pretty generic pattern of taking an array of id keys and return an array of key/value pairs.Calls a find method to get a record and then calls the display method on that record. You could use the sample code provided and inherit from AsyncDisplayMethodService or build your own class based on the sample. public class SampleService : AsyncDisplayMethodService { public SampleService() { this.TableName = "Sample"; this.FindStaticMethodName = "find"; } [WebMethod] public IDValuePair[] GetTotal(string[] expenseNumbers) { return this.CallDisplayMethod(expenseNumbers, "total"); } [WebMethod] public IDValuePair[] GetLineTotal(string[] expenseNumbers) { return this.CallDisplayMethod(expenseNumbers, "lineTotal"); } } EPAsyncDisplayMethod.ascx.cs: This is the code that you would include in your code behind. It registers the base javascript include.Then registers the initialization code that would be specific to you. var lineTotalAsync = new AsyncDisplayMethod(); // Just an ID for debugging. lineTotalAsync.ID = 'lineTotalAsync'; // This would be the asmx for your web service lineTotalAsync.WebService = 'SampleService.asmx'; lineTotalAsync.WebServiceOperation = 'GetLineTotal'; // IDSelector is a jQuery selector to find the ID to send to the web service // You can go to jquery.com to learn more about jQuery selectors. //GetBoundFieldCellSelector gets the basic jQuery selector to find an AxBoundField value // If you do not have ID as a visible field on the grid, // then you can create a template field with the ID value in a input type='hidden' field and // then you put a jQuery selector for that field as the IDSelector instead of calling GetBoundFieldCellSelector. lineTotalAsync.IDSelector =lineTotalAsync.GetBoundFieldCellSelector('LineNumber'); // lineTotalAsync is name of my display method that just returns an empty string as a placeholder lineTotalAsync.ValueSelector = lineTotalAsync.GetBoundFieldCellSelector('lineTotalAsync**') + ' > span'; // The default is cache the results of the display method in the browser, however if your value of the display method can change then // there is a method of invalidating the cache using CacheInvalidateSelector. In this example, the PriceUnit and QtyOrdered input fields can change the line total so // Here we have the jQuery selector to use when those fields change that we invalidate the cache. lineTotalAsync.CacheInvalidateSelector= lineTotalAsync.GetBoundFieldCellSelector('PriceUnit') + '> .AxInputField' + ', ' + lineTotalAsync.GetBoundFieldCellSelector('QtyOrdered') + '> .AxInputField'; lineTotalAsync.Initialize(); SampleDisplayMethod.ascx: Sample table: This the display method that will be called via JavaScript (lineTotalAsync and totalAsync). This also has a display method that just acts as a placeholder for the real display method (lineTotalAsync and totalAsync). ============== Источник: http://blogs.msdn.com/b/solutions/ar...y-loading.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
|