-
Notifications
You must be signed in to change notification settings - Fork 504
Cache when loading Options from URL #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'll make changes on loading options after v2.0.0 release. Thank you for your suggestion, I marked it as feature request, and evaluate it. |
Just one more thing to note on options fields. Options are stored in an object as key => value. When this field is rendered on screen, options are shown ordered according to the key value and there is no way to apply a user defined order. For instance, i need to show this options in the original order: I've patched your code already to fix this issue because I'm not sure if there is a workaround for it. Thank you, gbisheimer |
That's also a good point. Thanks. |
I think to allow user to define a function for options, for instance: CityId: { title: 'City', width: '12%', options: function(data) { //return an object, an array or a url. } } So, user can dynamically return options. data parameter will be an object and you can get record using data.record. Caching will be made only if return value is a url. Also, if url changes, a new cache will be created for new url (so, cached per url). Also you can clear cache with data.clearCache(); method. If this enough solution for your problems? |
Take a look at this plugin, Here you can define a option per field which enables or disables cache for I'll wait for your comments. 2013/1/18 hikalkan notifications@github.com
|
I see your solution, it's nice also. But I implemented a little more dynamic caching. An example uses caching: CityId: { title: 'City', width: '12%', options: '/Demo/CityList' } An example clears cache if some condition is true: CityId: { title: 'City', width: '12%', options: function(data) { if(some-condition) { data.clearCache(); } return '/Demo/CityList'; } } So, if we provide a boolean value indicates that whether this options is cached or not, it may cause a performance problem since jTable downloads options for each row in the table (not just for edit/create forms). Also I added some arguments that provides cascade drop downs. ContinentalId: { title: 'Continental', options: 'Demo/GetContinentalOptions', list: false }, CountryId: { title: 'Country', dependsOn: 'ContinentalId', //Countries depends on continentals. Thus, jTable builds cascade dropdowns! options: function (data) { if (data.source == 'list') { //Return url of all countries for optimization. //This method is called for each row on the table and jTable caches options based on this url. return 'Demo/GetCountryOptions'; } //This code runs when user opens edit/create form or changes continental combobox on an edit/create form. //data.source == 'edit' || data.source == 'create' return 'Demo/GetCountryOptions?continentalId=' + data.dependedValues.ContinentalId; }, list: false }, CityId: { title: 'City', width: '30%', dependsOn: 'CountryId', //Cities depends on countries. Thus, jTable builds cascade dropdowns! options: function (data) { if (data.source == 'list') { //Return url of all cities for optimization. //This method is called for each row on the table and jTable caches options based on this url. return 'Demo/GetCityOptions'; } //This code runs when user opens edit/create form or changes country combobox on an edit/create form. //data.source == 'edit' || data.source == 'create' return 'Demo/GetCityOptions?countryId=' + data.dependedValues.CountryId; } }, dependsOn option and data.dependedValues object provides efficient way of cascade drop downs. See the screenshot: |
It's a nice and very dynamic solution. I didn't realize that options are loaded from server for each table row when not cached. I think you clearCache() function should have effect only when entire table is loaded / redrawn and not every time options are loaded for a field. |
If your situation is that (A city may be added from another table/page), yes, you must use clearCache() when data.source is edit or create as like below: CityId: { title: 'City', width: '30%', dependsOn: 'CountryId', //Cities depends on countries. Thus, jTable builds cascade dropdowns! options: function (data) { if (data.source == 'list') { return 'Demo/GetCityOptions'; } data.clearCache(); return 'Demo/GetCityOptions?countryId=' + data.dependedValues.CountryId; } } This solved the problem: But, in this situation, still, there is a problem: When your table is open, if you open another window and add a new city for a country, then add a new student that lives in that city, then you return the first table (which cached the cities) and change the page to find new added student, City column in the table for new students is shown as undefined. For a solution, I can clear caches when user changes a page or reloads/refreshes the table, but this is also a performance cost for me. Maybe, I can do it optional, since not everyone come across such a scenario. Also, for a nicer solution, you can use 2 fields. One for listing (not edit/create), it contains the Name of City, not CityId. Second field is for create/edit. Only problem occurs on updates (synhronizing fields). This can be solved by returning name of the city from server after update (http://jtable.org/ApiReference#act-updateAction). I will think on a better hybrid solution for that. As you see, it may be complex such a simple problem :) |
Added cascade dropdowns and creating dynamically option list support. [#63, #94] Added field options: dependsOn and optionsSorting. Polish localization (by Grzegorz Zbucki). [#97] Lithuanian localization (by Vygandas Šimkus). [#103] Portuguese - Brazilian localization (by Renato Bigliazzi). [#129] Fixed some issues.
I found a solution for the problem desribed above (jTable caches options, user (from another window) adds a new option and a new record using this option, we change the page, get the new record but new option is not in the cache) var cacheKey = 'options_' + fieldName + '_' + optionsSource; //create a unique cache key
if (funcParams._cacheCleared || (!this._cache[cacheKey])) {
//if user calls clearCache() or options are not found in the cache, download options
this._cache[cacheKey] = this._buildOptionsFromArray(this._downloadOptions(fieldName, optionsSource));
this._sortFieldOptions(this._cache[cacheKey], field.optionsSorting);
} else {
//found on cache..
//if this method (_getOptionsForField) is called to get option for a specific value (on funcParams.source == 'list')
//and this value is not in cached options, we need to re-download options to get the unfound (probably new) option.
if (funcParams.value != undefined) {
var optionForValue = this._findOptionByValue(this._cache[cacheKey], funcParams.value);
if(optionForValue.DisplayText == undefined) { //this value is not in cached options...
this._cache[cacheKey] = this._buildOptionsFromArray(this._downloadOptions(fieldName, optionsSource));
this._sortFieldOptions(this._cache[cacheKey], field.optionsSorting);
}
}
} I checked the situation and re-download options if needed. |
Feature: Toolbar. [#188] Feature: 'Change page size' combobox. [#1, #128] Feature: 'Go to page' input. [#63] Feature: Multiple sorting of columns by holding CTRL key. [#48] Added options: multiSorting, gotoPageArea, pageSizes, pageSizeChangeArea, pageList and toolbar. Hungarian and Italian localizations [#179] Fixed some issues. [#209]
Feature: Toolbar. [volosoft#188] Feature: 'Change page size' combobox. [#1, volosoft#128] Feature: 'Go to page' input. [volosoft#63] Feature: Multiple sorting of columns by holding CTRL key. [volosoft#48] Added options: multiSorting, gotoPageArea, pageSizes, pageSizeChangeArea, pageList and toolbar. Hungarian and Italian localizations [volosoft#179] Fixed some issues. [volosoft#209]
Hey there, On a project I'm working on, I have a performance problem with 3 linked options lists (departments, zipcode and city names), and the fact that jTable issues an Ajax call for each and every row, as per the cascade drop downs example : options: function (data) { if (data.source == 'list') { //Return url of all countries for optimization. //This method is called for each row on the table and jTable caches options based on this url. return '/Demo/GetCountryOptions?continentalId=0'; } In my implementation (Classic ASP, IIS 6.0 w/ gzip compression enabled, sqlite database), each call is very costly and pointless since the response is always the same : a 88KB list of zipcodes. The result is a verry sloppy refreshing table when navigating the datas. I believe I have a jTable.org cache issue, since changing jQuery.ajaxSetup() options to GET instead of POST enables the browser to cache the server response, and the problem goes away. Unfortunately, it seems difficult to force the cache mecanism when using POST requests since - i'm quoting http://api.jquery.com/jQuery.post/ here "Pages fetched with POST are never cached, so the cache and ifModified options in have no effect on these requests". I tried to basically spit out the JSON without accessing the database, but jTable won't cache the datas anyway. Its hardly understandable since the url won't change either, and it has no parameters anyway. Overall, I'm very impressed by jTable and the work behind it, BTW, but unfortunately developping a small CRUD application with it took me more time than I expected. (I must add that I'm a very casual web developper, using bits for here and there to achieve my goals). Any suggestion is welcome. Keep up the good.work. Cheers. |
Hi Everyone, Best Regards, |
@shahrpt (Sulman) 👍 Hi, FYI, in my case, I ended up using mockjax to prefetch and cache datas locally, which then fools jtable Ajax calls for these datas. Cheers. |
Hi hikalkan,
It would be nice to have the posibility to clear cache contents on demand, or may be, just not store data retrieved from database into the cache, as it may be constantly changing and cache prevents showing new data.
Thank you. Cheers!,
gbisheimer
The text was updated successfully, but these errors were encountered: