| Page 1 of 1 | [ 4 posts ] |
|
I'm having an issue using YUI's example for adding a checkbox column to a Datatable. I used the example supplied on the website and what is happening is that the checkbox changes state and then seems to be immediately set back to the previous state by YUI.
table.delegate("click", function(e){ e.preventDefault(); // undefined to trigger the emptyCellValue var checked = e.target.get('checked') || undefined; this.getRecord(e.target).set('11', checked); }, ".yui3-datatable-data .yui3-datatable-col-11 input", table); ..... }, { key: "11", allowHTML: true, label: 'Check Box', formatter: chkbox }]; function chkbox(o) { return '<input type="checkbox" checked/>'; //Also, tried without checked. This way defaults it to checked.. undesired } I've also wrote my own event which checks the state of 'checked' and switches it...but again YUI switches it back giving it the appearance that the check box is doing nothing. Example this was taken from: http://yuilibrary.com/yui/docs/datatabl ... elect.html Things to note on this. I am using YUI 3.5.1. The example uses recordType: ['select', 'port', 'pname', 'ptitle'] in the datatable configuration. My datatable: //Create a new DataTable var table = new Y.DataTable({ columnset: columns, scrollable: 'y', data: initial_load, width: "900px", height:table_height+"px" }).render(selector); where initial_load is JSON data. I feel like there is some kind of disconnect between my data set and YUI's data table checkbox functionality. Thanks |
|
Not quite sure what the issue is here, maybe you can post your complete code on jsFiddle, pastie or a gist so somebody can scan it over.
A working fiddle of the YUI Checkbox example is at http://jsfiddle.net/blunderalong/YXFMK/. You're free to fork that fiddle, add your data and columns, and see where it stops working. Todd |
|
Todd,
Thank you for the repsonse. I have corrected this issue. I had delegated an event to 'td' on this table in 'domready'. In this it was calling preventDefault() which was causing the checkbox to not work properly. So now I have functioning checkboxes on my datatable, however, this datatable can also have data added to its modelList at some point which is clearing the state of the check boxes each time data is added. When data is added to the table the following is called: table.get('data').add(new_data, { silent: true}); table.syncUI(); Any direction on what this might be? |
|
@calamp
Not sure which version of DT you are using, I am assuming at least 3.5.0. If so, there was a new DT method (.addRow) that is preferred over using the "get('data').add(...)" approach you used. But in order to use that, you have to include the module "datatable-mutable" in your YUI use statement at the top (!). If you are using prior to 3.5.0, the process is different. Anyway, the whole purpose of that DT example was to show how to define a checkbox field in the recordType that maintains a "bound" data state, exactly so that if changes are made to the ModelList, it retains the setting. Not really sure why your approach didn't work. I updated the fiddle http://jsfiddle.net/blunderalong/YXFMK/3/ and both data.add and table.addRow worked fine. Checkout the above updated fiddle, sort on column 'Port No', then click "Add Record", and one is added to the top. If that doesn't work for you we may need to see some full code to help out. Todd |
| Page 1 of 1 | [ 4 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