You should be able to do what you want by customizing the lineFormat option:
// without jQueryvardatatable=newDataTable(document.getElementById('MyTable'),{lineFormat: function(id,data){// This is the default lineFormat:varres=document.createElement('tr');res.dataset.id=id;for(varkeyindata){if(data.hasOwnProperty(key)){res.innerHTML+='<td>'+data[key]+'</td>';}}// You can add contenteditable to the td you want:res.childNodes[2].contentEditable=true;returnres;}});// with jQuery$('#myTable').datatable({lineFormat: function(id,data){// This is the default lineFormat:varres=$('tr');res.data('id',id);for(varkeyindata){if(data.hasOwnProperty(key)){res.append($('<td>'+data[key]+'</td>');}}// You can add contenteditable to the td you want:res.children('td').eq(2).prop('contenteditable',true);returnres;}});
Thanks for the fast answer! But something is wrong. I added the jQuery code to my existing, and it doesn't work.
Here's my code:
$('#MyTable').datatable({pageSize: 20,sort: [true,true,true,true,true],filters: [true,true,'regexp','select',true],lineFormat: function(id,data){// This is the default lineFormat:varres=$('tr');res.data('id',id);for(varkeyindata){if(data.hasOwnProperty(key)){res.append($('<td>'+data[key]+'</td>');}}// You can add contenteditable to the td you want:res.prop('contenteditable',true);returnres;}});
// This add 'contenteditable' to the tr element:res.prop('contenteditable',true);// This (should) add 'contenteditable' to the second td element:res.children('td').eq(2).prop('contenteditable',true);
I am not a jQuery expert, but basically you are constructing the tr element inside lineFormat, so you can add contenteditable wherever you want, res simply contains the final tr element.
from datatable.
Comments (4)
You should be able to do what you want by customizing the
lineFormat
option:from datatable.
Thanks for the fast answer! But something is wrong. I added the jQuery code to my existing, and it doesn't work.
Here's my code:
from datatable.
Sorry, my jQuery example was wrong:
I am not a jQuery expert, but basically you are constructing the
tr
element insidelineFormat
, so you can addcontenteditable
wherever you want,res
simply contains the finaltr
element.from datatable.
Thanks for your time!
from datatable.
Related Issues (20)
Recommend Projects
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
Recommend Topics
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
web
Some thing interesting about web. New door for the world.
server
A server is a program made to process requests and deliver data to clients.
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Visualization
Some thing interesting about visualization, use data art
Game
Some thing interesting about game, make everyone happy.
Recommend Org
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.