javascript - Inline editing for HTML table -


i have following jquery function displays table.

$(function() {     $("#table-contact > tbody").html("");     $.ajax({             "url" : '/contact/' + id,              type: 'get',              success: function(data) {              $.each(data.details, function(k, v) {                   var dataarr = new array();                   dataarr.push('<label class="id">'+ v.id + '</label>');                   dataarr.push('<select data-val=' + item.course + ' ><option>science</option><option>economics</option><option>literature</option><option>maths</option><option selected>' + item.course + '</option></select>');   // here getting 2 values selected option                   dataarr.push('<input type="text" name="category">' + v.catg + ' </disabled>');                   dataarr.push('<label class="name">'+ v.name + '</label>');                   $('#table_contact > tbody:first').append('<tr><td>' + dataarr.join('</td><td>') + '</td></tr>');               });           },     }; 

i need inline editing 2nd , third column - upon clicking these fields, display dropdown box select. , on clicking 'save', needs save data table.

enter image description here

check my jsfiddle example, doesn't take care of populating table, edit/save it: http://jsfiddle.net/vittore/wgtf6y24/

also, rather style select simple input box when state not :active , style normal select :active , :focus users able tab through table. (see example of such styling in snipped below)

we did table that, need click on table cell edit it, pain in neck users.

var t = $('table'), inputs = t.find('input, select'), b = $('button'), ta = $('#save')    t.on('change', 'input, select', (e) => {        $el = $(e.target)        $el.data('val', $el.val())        console.log($el.val())  })    b.on('click', () => {    	var data = []    	inputs.each((i,inp) => data.push($(inp).data()) )  	ta.text(json.stringify(data))  })
input {border : 1px solid #fff;margin:0; font-size:20px; }  input:focus,input:active,input:hover { outline: 1px solid #eee; background-color:#eee; }  select { border: 1px solid #fff; margin:0; padding:0; font-size:20px; border:0;      -webkit-appearance: none;     -moz-appearance: none;  }    table { border : 1px solid #999; border-collapse:collapse;border-spacing:0; }  table td { padding:0; margin:0;border:1px solid #999; }  table th { background-color: #aaa; min-width:20px;border:1px solid #999; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <table>      <tr>          <th></th>          <th>a</th>          <th>b</th>          <th>c</th>      </tr>      <tr data-row="0">          <th>1</th>          <td><input disabled type="text" data-row="0" data-col="0" data-val="a" value="a" /></td>          <td>  <select data-row="0" data-col="1" data-val="yes"><option>yes</option><option>no</option></select></td>          <td><input type="text" data-row="0" data-col="2" data-val="c" value="c" /></td>      </tr>      <tr data-row="1">          <th>2</th>          <td><input disabled type="text" data-row="1" data-col="0" data-val="d" value="d" /></td>          <td><select data-row="1" data-col="1" data-val="no"><option>yes</option><option selected>no</option></select></td>          <td><input type="text" data-row="1" data-col="2" data-val="f" value="f" /></td>      </tr>      <tr data-row="2">          <th>3</th>          <td><input disabled type="text" data-row="2" data-col="0" data-val="g" value="g" /></td>          <td><select data-row="2" data-col="1" data-val="no"><option>yes</option><option selected>no</option></select></td>          <td><input type="text" data-row="2" data-col="2" data-val="i" value="i" /></td>      </tr>  </table>    <div name="data" id="save" cols="30" rows="10"></div>  <button>save</button>


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -