luis930114 / jquery-datatables-editable

Automatically exported from code.google.com/p/jquery-datatables-editable
0 stars 0 forks source link

how do you format numeric data as cells are edited? #92

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I have a column of data that is currency, so it looks best if we maintain two 
decimal points.  This javascript formatting does the trick, but I cannot figure 
out how to apply it to the edited contents when the cell is updated.  It is a 
realy basic question, but I am just figuring datatables-editable out.

(parseFloat(value)).toFixed(2);

So far this is what I have in aoColumns for this cell.
onblur: 'submit', cssclass: "number" 

I was trying to use sUpdateURL to apply the format, but I cannot get it to 
work.  What is the best approach to reformatting or otherwise adjusting data 
after it has been modified?

Original issue reported on code.google.com by alindzo...@gmail.com on 16 Feb 2012 at 4:22

GoogleCodeExporter commented 8 years ago
Sorry not a defectjsut a question, I did not notice that selection before I 
saved.  I cannot figure out how to edit so I cannot correct the mistake.

Original comment by alindzo...@gmail.com on 16 Feb 2012 at 4:24

GoogleCodeExporter commented 8 years ago
Hi,

If problem is in formatting data that should be displayed, maybe you can sort 
this out in the DataTables plugin directly. In DT plugin you can define 
fnRender function that will be used to render/format cell content in some 
column. As an example, to define that cell content of column 1 should be 
wrapped in span with class money and add dollar sign at the end of value you 
might set following in the DataTables call: 

$('#example').dataTable( {
        "aoColumns": [ 
            null,
            { "fnRender": function ( oObj ) {
                return '<span class="money">' + oObj.aData[1] +'$ </span>';
            } },
            null
        ]
    } );

You can see more info about fnRender on datatables site.

However, in that case you will still have a simple text box for inline editing. 
If you want to have inline editor that allows formatted input maybe you can 
replace standard jeditable input with some custom input type see for example 
masked input on http://www.appelsiini.net/projects/jeditable/custom.html 

Let me know did this helped you.

Jovan

Original comment by joc...@gmail.com on 16 Feb 2012 at 6:46