⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

bug: Save and go back to list



watis

watis
  • profile picture
  • Member

Posted 21 September 2012 - 11:10 AM

Hi!

First of all, thank you for GC, it's really cool!

I found a strange bug with the "Save and go back to list".
Using it after 6x times I get error message:
[b] Bad Request[/b]

[color=#000000][font=Times New Roman][size=1]Your browser sent a request that this server could not understand.[/size][/font][/color]
[color=#000000][font=Times New Roman][size=1]Size of a request header field exceeds server limit.[/size][/font][/color]

[attachment=294:bug_save_and_back_to_list.JPG]

The bug is not on the "Save" button, but sometimes I need to hide it.
It seems that, the bug is only in the datatables theme.

[color=#282828][font=helvetica, arial, sans-serif]Thanks in advance![/font][/color]

saulimus

saulimus
  • profile picture
  • Member

Posted 21 September 2012 - 12:10 PM

I ran into this problem as well. It occurs because the DataTables cookie exceeds the 4kB limit.
DataTables keeps the settings of each table in storage with either cookies or local storage.
This becomes a problem because it works by default by looking at the current URL for the cookie name.
Because GroceryCrud uses urls like sometable/success/3, sometable/success/2, the amount of data becomes too big (over 4kB) at some point.
Some solutions:
1. Disable state saving altogether:
http://datatables.net/usage/features#bStateSave
2. Use Datatables' localStorage, which has no limit on the amount of data
http://datatables.net/blog/localStorage_for_state_saving
3. Check if the url includes /success/(number) and don't save data for that url
OR: figure out what the original url is and use that

This is how I did myself: (datatables.js)

// http://mathiasbynens.be/notes/localstorage-pattern
function localstorage_supported()
{
var storage,
fail,
uid,
supported;
try {
uid = new Date;
(storage = window.localStorage).setItem(uid, uid);
fail = storage.getItem(uid) != uid;
storage.removeItem(uid);
fail && (storage = false);
} catch(e) {}
supported = false;
if(storage) supported = true;
return supported;
}
$(document).ready(function() {
var use_storage = localstorage_supported();
var pathname = window.location.pathname;
if(if(pathname.indexOf("/success/") != -1) use_storage = false;
}
// ...
oTable = $('#groceryCrudTable').dataTable({
// ...
// specify if using state saving
"bStateSave": use_storage,
// using local storage for state saving
"fnStateSave": function (oSettings, oData) {
localStorage.setItem( 'DataTables_'+window.location.pathname, JSON.stringify(oData) );
},
"fnStateLoad": function (oSettings) {
return JSON.parse( localStorage.getItem('DataTables_'+window.location.pathname) );
},
// ...
});

saulimus

saulimus
  • profile picture
  • Member

Posted 21 September 2012 - 12:20 PM

I hate this comment system.. I cannot paste code with tabs in it... also, if I try to edit the post again the code loses all tabs and leading spaces.. how annoying is that!

watis

watis
  • profile picture
  • Member

Posted 21 September 2012 - 12:57 PM

Thank you saulimus! The modifed [color=#282828][font=helvetica, arial, sans-serif]datatables.js works perfectly.[/font][/color]

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 23 September 2012 - 19:59 PM

Thank you [member='saulimus'] for the help. Really helpful post. I just added a bit of similar code at the master revision so this fix will be included at 1.3.2 as well. Whoever is interested at the changes take a look at: https://github.com/scoumbourdis/grocery-crud/issues/101

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 23 September 2012 - 20:03 PM

[quote name='saulimus' timestamp='1348230058' post='3571']
I hate this comment system.. I cannot paste code with tabs in it... also, if I try to edit the post again the code loses all tabs and leading spaces.. how annoying is that!
[/quote]

I just checked it and you are right. I will report it to the forum developers or I will search for a quick fix for that. I think this happens after the update of the forum.

Thanks to mention that.