Server side filtering

8 posts, 0 answers
  1. Noel
    Noel avatar
    11 posts
    Member since:
    Jun 2013

    Posted 29 Jun 2013 Link to this post

    I am trying to perform server-side filtering to retrieve the data from everlive with userid=currentuser. But the program doesn't  run after inserting the filter function. Is there any way I can retrieve the rows only with userid=currentuser. Here is my code.

    var tempDataSource = new kendo.data.DataSource({
    type: 'everlive',
                
    schema: {
    model: tempModel
    },
                
    transport: {
    typeName: 'Activity'
    },
    serverFiltering: true,
                filter: { logic: "and", filters: [ { field: "UserId", operator: "eq", value: usersModel.currentUser.data.Id } ] }
    });

  2. Ivan
    Admin
    Ivan avatar
    111 posts

    Posted 01 Jul 2013 Link to this post

    Hi,

    I have tested your filter in the Everlive project template and everything works just fine when using a hard coded user ID. Since I am not familiar with your code, my guess is that 'usersModel.currentUser.data.Id' is not defined by the time you create your data source.

    On a side note, you can easily debug such problems yourself using the simulator. You can read more information regarding this in our documentation: 'Debugging with Graphite', and 'Debugging with Mist'.

    Regards,
    Ivan
    Telerik

    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Missed our first webinar, watch it here.
    Share feedback and vote for features on our Feedback Portal.
  3. Noel
    Noel avatar
    11 posts
    Member since:
    Jun 2013

    Posted 01 Jul 2013 Link to this post

    Thank you very much for your response. I am new to kendoUI and the concept of MVVM.

    You are right that the code runs fine when I hard code a UserID that matches the one in everlive and the fact that 'usersModel.currentUser.data.Id' is not defined when the datasource is created. From the debugger, it seems like my datasource is created when the app is opened. Is there anyway to create the datasource when the view is loaded? 


  4. Noel
    Noel avatar
    11 posts
    Member since:
    Jun 2013

    Posted 01 Jul 2013 Link to this post

    Thanks Ivan! I am new to kendoUI and the concept of MVVM. 
    You are right that the code runs fine when I hard code a UserID that matches the one in everlive and the fact that 'usersModel.currentUser.data.Id' is not defined when the datasource is created. From the debugger, it seems like my datasource is created when the app is opened. Is there anyway to create the datasource after user login?

  5. Ivan
    Admin
    Ivan avatar
    111 posts

    Posted 04 Jul 2013 Link to this post

    Hi,

    Perhaps the simplest solution in your case is to create the DataSource without a filter, and then apply the filter when the current user becomes available after login. I have tested this approach in our Everlive template project and it works. Since the JavaScript code is relatively large I am posting here only the simple modification I have made:

    var activitiesViewModel = (function () {
        // Code removed for brevity.
        usersModel.currentUser.bind("change", function(){
            activitiesModel.activities.filter({
                field: "UserId",
                operator: "eq",
                value: usersModel.currentUser.data.Id
            });
        });
        // Code removed for brevity.
    }());

    Every time the current user is changed the binding should trigger the above logic which applies the correct filter to the DataSource. That should also work correctly when the current user logs out and another user logs in instead. Hope this helps.

    Regards,
    Ivan
    Telerik

    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Missed our first webinar, watch it here.
    Share feedback and vote for features on our Feedback Portal.
  6. Noel
    Noel avatar
    11 posts
    Member since:
    Jun 2013

    Posted 04 Jul 2013 Link to this post

    Hi Ivan,

    Thanks for the help. Your code works; however, in the debug mode, I see information about other users get transferred to the person's phone.

    I am concerned about two things.
    1.) What happens when the table in my database gets big 
    2.) What about security issues? 

    Should I stick with server-side filtering? 

    Noel 
  7. Noel
    Noel avatar
    11 posts
    Member since:
    Jun 2013

    Posted 04 Jul 2013 Link to this post

    Please ignore my last reply.

    I can use your code and leave the "serverFiltering: true" flag in there to do server side filtering. Thank you very much Ivan!
  8. Noel
    Noel avatar
    11 posts
    Member since:
    Jun 2013

    Posted 04 Jul 2013 Link to this post

    Please ignore my last reply
    I can use your code and leave the  serverFiltering: true flag in there to do server side filtering. Thanks Ivan!
Back to Top