| Page 1 of 1 | [ 8 posts ] |
|
I am using YUI2 datatable.
All the column configs and data gets loaded dynamically from the server side in JSON format and datatable gets prepared from parsed JSON string. After loading the datatable I have an Advanced Search option which can have more number of fields provided then present in datatable at the time. So after filling up all the data in Advanced Search form control go backs to the server again and filters the data according to search crieteria and prepares the datatable again. But here because of performance issue I am not preparing or instantiating the datatable again but I am just reseting the record set and replaces the data with new record set data from the returned JSON string. I am using below code to replace the data var resultData = JSONResponse.resultSet.results; myDataTable.getRecordSet().reset(); myDataTable.getRecordSet().setRecords(resultData); myDataTable.refreshView(); I have some columns which have dates, numbers and columns. The problem is When I refresh the data after advanced search data table is not retaining the formatters for date,number and currency. I am using inbuilt formatters of datatable. Because of this it creates the sorting problem on the datatable. If I dont update or refresh the data, all the things are working fine. Am I missing something here when I refreshj the data ? |
|
Actually, what you are probably missing there are not the formatters but the parsers on the DataSource side, which you are not using. You should use the same DataSource to fetch the new data so the same parsers get called all the time.
See: http://www.satyam.com.ar/yui/#requery For most cases, the 2.6 version is fine, the 2.8 version added support for server side sorting and pagination. Anyway, please do read the comments. |
|
Thank you very much for the reply..
I already looked at your requery example before posting this question Actaully my problem is, I am preparing all the advance search field dynamically based on the user preferences saved in configuarations. So all the HTML will be the dynamic one. So I have created a framework which will generate the HTML code from JAVA based on the field type (textbox,multiselect,select etc.) and also all the lables and names will come from configuartion. All this will be open up in the YUI dialog box. Now when user fill up the data in above dialog box and submit it, page gets submitted to server and some data validation will hapen there and if some error is there it will straight away those errors on dialog box. If there are no errors then it will proceed further and get all the data from the dialog box which user has enterd. Here I am using the JSP useBean utility which will set all the data automatically in POJO class and I can then refer it to fetch data from database. After getting the user entered data I am calling one servlet which will then prepare the JSON result data and control comes back in success handler of the dialog box. There I am parsing the JSON result set and setting it in recordset. So here I am little bit confused about how can I use requery because actual query is firing from the other page. One note I forgot that the problem is not with formatter but it is with the parsers which I am using So I was thinking that is there anyway that I can again parse the data with the original datasource from the success handler of advance search dialog box ? |
|
I am lost with what happens in between the client and the server. Anyway, a couple of things that might help.
Once you received your data on the client side, instead of setting the record directly, you can use a local DataSource to read the data from the decoded JSON. Alternatively, if it is the parsers you need, they are plain functions that receive the raw data and returned the parsed version of it. They are all stored in the static Parser property: http://developer.yahoo.com/yui/docs/YAH ... rce.Parser So, you can parse your data yourself using those same parsers like: var parsedNumber = YAHOO.util.DataSource.Parser.number(rawNumber); or you can use your own parsers just as well. |
|
For this I have to iterate whole result set from decoded JSON resultset and then apply the corresponding parser to each column data and append it to the datatable data again..Please Correct me if I am wrong.
I was lloking for a method like if I can give the resulted data and it can return me the parsed data according to type of each column. I am providing some sample data which I am going to have as JSON string {"resultSet":{"columnList":[{"key":"test1","label":"Test Data","formatter":"TestHyperLink"},{"key":"test date","label":"This is a date",formatter":"date","parser":"date"},{"key":"testNumber","label":"This is a test number","formatter":"number","parser":"number"}], "results":[{"test1":"testString","testdate":"Tue Aug 31 00:00:00 EDT 2010","testNumber":"12345.32"},{"test1":"testString2","testdate":"Mon Aug 30 00:00:00 EDT 2010","testNumber":"362569.32"}]} Here I have the different parser defined for each attribute. So I have this config data in my returned JSON string. Could you please suggest how can I make the most effective use of this data for parsing again ? Note : I have the data table refernce with me which I can use at the point of parsing above data. |
|
You are right, you would have to loop through the whole result set. That is what DataSource would do if you let it do it for you. I don't think there is any way around it.
You could skip some of the parsing, though. Numbers don't need to be quoted in a JSON string, that allow you to skip on a column parser since the JSON parser would make it a number right away. Booleans and null don't need to be quoted either, that can save you some work. Then it is just a matter of optimizing the loop, but loop you will have to. |
|
Okay..
thank u very much for ur suggestions.. just a one thing about which I was curious.. when I m doing parsing of any date field initially,it gives correct date format like mm/dd/yyyy.. but when I am doing manual parsing with datasource.parseDate method it does return me a timestamp format.. is there any other thing i have to do to get the desired date format ? now when I am going to iterate whole resultset, my problem is i dont have static keys and data every time..it depends on some user selections at run time.. but I do have a column list object where all the column information is.. here first i have to iterate resultset array for data but to iterate it I need keys name rite.. so my approach will be to iterate resultset object parallely to columnlist from where i can get key name like var keyName = columnList[i].key and pass it to resultset[keyName] to get the value and then parse it and store it in one array to later provide it to datatable resultset. Please let me know if u think that i need some optimization on this or u have any better approach on this.. may be I would have a very large amount of data.. Really appreciate ur help.. |
|
I have resolved the issue
Implemented following method Sample data : {"resultSet":{"columnList":[{"key":"test1","label":"Test Data","formatter":"TestHyperLink"},{"key":"test date","label":"This is a date",formatter":"date","parser":"date"},{"key":"testNumber","label":"This is a test number","formatter":"number","parser":"number"}], "results":[{"test1":"testString","testdate":"Tue Aug 31 00:00:00 EDT 2010","testNumber":"12345.32"},{"test1":"testString2","testdate":"Mon Aug 30 00:00:00 EDT 2010","testNumber":"362569.32"}]} Here resultData is resultSet.results and columnList is resultSet.columnList function parseRowData (resultData,columnList){ var parsedData = resultData ; for(var i=0; i< resultData.length; i++ ){ for(var j = 0; j < columnList.length; j++){ var columnObj = columnList[j]; var parser = columnObj.parser; if(parser != ""){ if(parser == "date"){ parsedData[i][columnObj.key] = YAHOO.util.DataSource.parseDate(resultData[i][columnObj.key]); }else if(parser == "number"){ parsedData[i][columnObj.key] = YAHOO.util.DataSource.parseNumber(resultData[i][columnObj.key]); } }else{ continue; } } } return parsedData; } @ Satyam : Thank you so much for your help... |
| Page 1 of 1 | [ 8 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group