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

User preference loading from Database

4 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jerry
Top achievements
Rank 1
Jerry asked on 21 Jul 2014, 04:21 AM
Hi, i've been trying to get user grid preference saving following this link:

http://jsbin.com/anisip/31/edit

It's been very helpful so far with saving the data to my database.

However, i'm trying to load the saved data now but i cant seem to get it working.


In my database, i've saved the "state" of the object which looks similar to this:
"{"group":[{"field":"Supplier","dir":"asc","aggregates":[]}]}"

When i load my page i try to load the user grid preference from the database (due to filtering needed as soon as the window loads, i have this method in the window.load() function).

                var grid = $("#Grid").data("kendoGrid");

                // Load grid preferences.
                $.post("Home/LoadGridPreference", { forScreen: "" }, function (data) {
                    var state = JSON.parse(data);
                    if (state) {
                        grid.dataSource.query(state);
                    } else {
                        grid.dataSource.read();
                    }
                });

I have checked that the data i get in "state" is indeed the same as before i stringified the grid information.

However when it gets to the stage grid.dataSource.query(state), nothing seems to happen , i cant see any ordering that i have saved in the database.

Also, to test out whether its the "state" value not being set correctly, i have tried to manually override this by using the exact values from when the "state" value was set. i.e. i have tried this grid.dataSource.query("{"group":[{"field":"Supplier","dir":"asc","aggregates":[]}]}")

Yet this does not work either. 

I can see that it's trying to do something as this seems to make the row counter (located on the bottom right of the screen) to say NaN - NaN of 3 items.


The example on JSBin works perfectly using cookies, but why isn't this working when i implement this on my project and save the grid preferences into the database?


Thanks

4 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 22 Jul 2014, 01:52 PM
Hello Jerry,

I'm afraid that it is not clear what may be the cause for such behavior judging from the provided details. However, I have modified the test page you have referred to, in order to demonstrates similar to the described implementation. Please take a look and see if it helps in your own implementation. 

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jerry
Top achievements
Rank 1
answered on 22 Jul 2014, 11:16 PM
Hi Rosen


Thanks for your reply.


I've had a look at your jsbin and tried changing my post method to a get so it looks like this:

// Load grid preferences.
                $.get("Home/LoadGridPreference", { forScreen: "manager" }, function (data) {
                    var state = JSON.parse(data);
                    if (state) {
                        grid.dataSource.query(state);
                    } else {
                        grid.dataSource.read();
                    }
                }, "json");

After doing so, ive got an error saying: 

Uncaught TypeError: Cannot read property 'length' of undefined http://localhost:49616/Scripts/kendo/2014.1.528/kendo.all.min.js

It seems the main difference between the $.post and get method is, post gives me the string "{"group":[{"field":"DeliveryAddress","dir":"asc","aggregates":[]}]}" whereas $.get gives me an object.

I can see your jsbin example also returns an object with similar looking values so i'm quite stumped as to why this would be happening.

I've attached a file showing what the object looks like in debug tools.

Thanks
0
Jerry
Top achievements
Rank 1
answered on 23 Jul 2014, 04:36 AM
Hi Rosen,


I've played around with this a bit more and ive found that using the callback data directly (instead of parsing it) doesnt cause the debug issue anymore.

However, i now see that the number on the bottom says NaN - NaN of 2 items and the columns are not grouping as usual.

Could it be because im just trying to load the column states using grid.dataSource.query? (i.e. im skipping saving and loading of columnstates and emprows) or because one of my column headers is binding to a clientside property?

Thanks again
0
Rosen
Telerik team
answered on 23 Jul 2014, 11:15 AM
Hi Jerry,

I suspect that the pager issue you have described is caused by the fact that the paging information (page and pageSize) is not set, thus it is being removed during the query method call and no paging on the DataSource data is applied. Setting the paging info as part of the persisted state should address the issue in question.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Jerry
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Jerry
Top achievements
Rank 1
Share this question
or