hkalbertl / jquery.appendGrid

The dynamic table input JavaScript plugin
https://appendgrid.azurewebsites.net
MIT License
148 stars 76 forks source link

CtrlOptions behind a method to root, behind the initData can root method #96

Closed ObjectXhy closed 7 years ago

ObjectXhy commented 7 years ago

$('#tblAppendGrid').appendGrid({ caption: 'My CD Collections', initRows: 1, columns: [ { name: 'Album', display: 'Album', type: 'text', ctrlAttr: { maxlength: 100 }, ctrlCss: { width: '160px' }, onChange: function (evt, rowIndex) { alert('You have changed the value of Album at row ' + rowIndex); } }, { name: 'Artist', display: 'Artist', type: 'text', ctrlAttr: { maxlength: 100 }, ctrlCss: { width: '100px'} }, { name: 'Year', display: 'Year', type: 'text', ctrlAttr: { maxlength: 4 }, ctrlCss: { width: '40px'} }, { name: 'Origin', display: 'Origin', type: 'select', ctrlOptions: { 0: '{Choose}', 1: 'Hong Kong', 2: 'Taiwan', 3: 'Japan', 4: 'Korea', 5: 'US', 6: 'Others'} }, { name: 'Poster', display: 'With Poster?', type: 'checkbox', onClick: function (evt, rowIndex) { alert('You have clicked on the With Poster? at row ' + rowIndex); } }, { name: 'Price', display: 'Price', type: 'text', ctrlAttr: { maxlength: 10 }, ctrlCss: { width: '50px', 'text-align': 'right' }, value: 0 } ], initData: [ { 'Album': 'Dearest', 'Artist': 'Theresa Fu', 'Year': '2009', 'Origin': 1, 'Poster': true, 'Price': 168.9 }, { 'Album': 'To be Free', 'Artist': 'Arashi', 'Year': '2010', 'Origin': 3, 'Poster': true, 'Price': 152.6 }, { 'Album': 'Count On Me', 'Artist': 'Show Luo', 'Year': '2012', 'Origin': 2, 'Poster': false, 'Price': 306.8 }, { 'Album': 'Wonder Party', 'Artist': 'Wonder Girls', 'Year': '2012', 'Origin': 4, 'Poster': true, 'Price': 108.6 }, { 'Album': 'Reflection', 'Artist': 'Kelly Chen', 'Year': '2013', 'Origin': 1, 'Poster': false, 'Price': 138.2 } ],

hkalbertl commented 7 years ago

Hi ObjectXhy,

Sorry that I was out of town last week so I hope it is not too late to reply your question.

Actually, I don't understand your question. Can you describe in more detail? It would be better to give me some sample code. Thanks!

ghost commented 7 years ago

Hi ObjectXhy, Are trying to get control options from a datasource? Then here a way to do that. var mylist; $.ajax({ type: "POST", url: "myurl.aspx/getlist", data: '{}', //replace braces by JSON.stringify({ paramname: "paramdata" }), //if you need to pass parameter contentType: "application/json; charset=utf-8", dataType: "json", success: OnSuccess, failure: function (response) { alert(response.d); } }); function OnSuccess(response) { //gets List mylist= response.d;

//call your appendgrid here

$('#tblAppendGrid').appendGrid({ caption: '', initRows: 1, columns: [ { name: 'Origin', display: 'Origin', type: 'select', ctrlOptions: mylist, ctrlCss: { width: '100px'} } ] //rest of your code below }