Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
105
FunctionDataSource or something similar
posted

I am implementing IG Grid in HTML and I am using my own client side cache management widget so whenever Grid needs data I want it to call my function so I can get data from my own DataManager widget.

Ie I do NOT want to give controller URL to the Grid I want to give a function instead, I tried functionDataSource and it gives a javascript error "Unknown data source type:function" in ig.ui.min.js

I want server side filtering, sorting and paging so I cannot just give an array of objects received by my DataManager, I want a two way binding so if some one sorts on Grid it should call my function with the sort column name or entire url and I can fetch data myself or get it from cache.

The documentation of FunctionDataSource http://help.infragistics.com/jQuery/2011.2/ig.functiondatasource lacks everything, also there is no documentation how we can set the data on databinding event

Please help ASAP

 

 

Parents
No Data
Reply
  • 6279
    Verified Answer
    posted

    Hello,

    I have to agree that the help for the FunctionDataSource isn't as descriptive as it could be, but this particular case has a couple of alternative solutions:

    1. You can make an implicit FunctionDataSource object for the igGird by setting the following options when configuring the igGrid widget:

    dataSourceType: "function",

    dataSource: dataManagerObject.getDataForGrid,

    localSchemaTransform: false

    Let me elaborate on these a bit: by setting the dataSourceType option to "function" you tell the igGrid's internal DataSource object to treat the incoming data as a reference to a function.

    Then you pass the actual function reference in the dataSource option.

    Finally, since the FunctionDataSource does not support transformation of the source data (albeit having an explicitly-defined FunctionDataSource with a schema supports this), you will need to make sure that the grid takes the function's output "as is" (thus you need to set the localSchemaTransform option to false).

     

    2. You can pass a call to your DataManager object's function to the grid - the options of the igGrid that are necessary in this case are as follows:

    dataSourceType: "json",

    dataSource: dataManagerObject.getDataForGrid(),

     

    Making the call to your function is nearly identical to passing the reference, the outcome is the same and there is no change in performance. Generally speaking, it's more convenient to pass an object (the output of a function in this case) to the igGrid so we have stressed on that scenario in the samples.

    => I want server side filtering, sorting and paging so I cannot just give an array of objects received by my DataManager, I want a two way binding so if some one sorts on Grid it should call my function with the sort column name or entire url and I can fetch data myself or get it from cache.

    This is a tricky situation, because the use case would be:

    1. The grid is bound to a remote URL

    2. Paging/Sorting/Filtering are also remote

    In this situation the igGrid (and igDataSource) use the URL passed as a source of data in order to encode Paging/Sorting/Filtering-orientated requests when any of the those features is used. There isn't a possibility to have a URL for each feature so that it can operate remotely even when the igGrid is powered by locally-received data.

    Thus having local data passed to the grid and remote features requires the following effort:

    1. You will need to explicitly set each feature's type option to "remote"

    2. You would need to extend the igDataSource class (just like the FunctionDataSource does so for example) and override the following functions in it:

    • dataBind
    • _remoteData

    In them you can (and should) customize the logic so that based on the currently used feature, you can create your tailor-made HTTP request or call to the DataManager you mentioned and wait for the data to arrive so you can pass it to the igGrid which will use this custom DataSource (let's call it DataManagerDataSource for the sake of this example).

    It might sound very hard, but in my opinion you really need to step on three pillars in order to do this:

    1. Know what are the input parameters of the dataBind and _remoteData functions

    2. Your custom logic will decide whether to pull data from the DataManager cache or perform a fresh server-side call (based on the params from the previous pillar)

    3. Know what should be the output of the dataBind and _remoteData functions(methods)

    dataBind in specific is thoroughly documented (https://www.igniteui.com/help/igdatasource-igdatasource) and _remoteData  is actually needed when you need to pull data from the server-side.

     

    Thus, you should be able to work with your DataManager cache and server-side logic without too much trouble.

     

    If there's anything else we can do to assist you, please let us know.

     

    Cheers,

    Bobislav

Children