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

Server side filtering

7 Answers 99 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Noel
Top achievements
Rank 1
Noel asked on 30 Jun 2013, 02:08 AM
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 } ] }
});

7 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 01 Jul 2013, 10:21 AM
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.
0
Noel
Top achievements
Rank 1
answered on 01 Jul 2013, 11:33 PM
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? 


0
Noel
Top achievements
Rank 1
answered on 01 Jul 2013, 11:38 PM
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?

0
Ivan
Telerik team
answered on 04 Jul 2013, 11:53 AM
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.
0
Noel
Top achievements
Rank 1
answered on 04 Jul 2013, 06:10 PM
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 
0
Noel
Top achievements
Rank 1
answered on 04 Jul 2013, 11:11 PM
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!
0
Noel
Top achievements
Rank 1
answered on 04 Jul 2013, 11:11 PM
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!
Tags
General Discussion
Asked by
Noel
Top achievements
Rank 1
Answers by
Ivan
Telerik team
Noel
Top achievements
Rank 1
Share this question
or