I'm not sure if this is easily doable would appreciate any advice on how to solve this problem.

I'm not sure if this is easily doable would appreciate any advice on how to solve this problem.

mike92117mike92117 Posts: 38Questions: 11Answers: 1

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

This question has an accepted answers - jump to answer

Answers

  • mike92117mike92117 Posts: 38Questions: 11Answers: 1

    I have an application where I'm editing a simple table that is comprised of values of temperature, pressure and other values that have measurement units. In this case, the table is storing the values in English units, e.g., temperature in Fahrenheit degrees, pressure in pounds per square inch, etc.

    The web application has a setting for whether the user wants to use Metric or English. So temperature could be entered (and edited) as degrees Centigrade. But I'm wondering if there is a way I can hook into the editor API to convert the values on a GET to Metric and then convert from Metric back to English so it gets persisted to the database correctly (in English). I'm working in C# and the API call /hx/hxstatepoints, returns ENGLISH values and on POST needs to persist ENGLISH values.

    I would also like to have the labels accurately reflect the current unit system the user has chosen so it shows Temperature, °F or Temperature, °C as a label.

    This is my html/javascript

            <table id="dtHXState" class="display" style="width:100%">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Cold fluid</th>
                        <th>Tc</th>
                        <th>Pc</th>
                        <th>Mc</th>
                        <th>Hot fluid</th>
                        <th>Th</th>
                        <th>Ph</th>
                        <th>Mh</th>
                    </tr>
                </thead>
            </table>
    
    <script type="text/javascript" class="init">
        var editor;
        var tclbl;
        $(function () {   
            editor = new $.fn.dataTable.Editor({
                ajax: '../HX/HXStatePoints',
                table: "#dtHXState",
                dataType: 'json',
                fields: [{
                    label: "Name",
                    name: "HXStatePoint.Name"
                }, {
                    label: "Cold fluid",
                    name: "HXStatePoint.ColdFluidID",
                    type: "select",
                    placeholder: "Select a fluid"
    
                }, {
                    label: "Tc",
                    name: "HXStatePoint.Tc"
                }, {
                    label: "Pc",
                    name: "HXStatePoint.Pc"
                }, {
                    label: "Mc",
                    name: "HXStatePoint.Mc"
                }, {
                    label: "Hot fluid",
                    name: "HXStatePoint.HotFluidID",
                    type: "select",
                    placerholder: "Select a fluid"
                }, {
                    label: "Th",
                    name: "HXStatePoint.Th"
                }, {
                    label: "Ph",
                    name: "HXStatePoint.Ph"
                }, {
                    label: "Mh",
                    name: "HXStatePoint.Mh"
                }
                ]
            });        
            $('#dtHXState').DataTable({
                dom: "Brftip",
                ajax: "../HX/HXStatePoints",
                type: 'POST',
                columns: [
                    { data: "HXStatePoint.Name" },
                    { data: "ColdFluid.Name" },
                    { data: "HXStatePoint.Tc" },
                    { data: "HXStatePoint.Pc" },
                    { data: "HXStatePoint.Mc" },
                    { data: "HotFluid.Name" },
                    { data: "HXStatePoint.Th" },
                    { data: "HXStatePoint.Ph" },
                    { data: "HXStatePoint.Mh" }
                ],
                select: true,
                buttons: [
                    { extend: "create", editor: editor },
                    { extend: "edit", editor: editor },
                    { extend: "remove", editor: editor }
                ]
            });
        });
    </script>
    
  • colincolin Posts: 15,146Questions: 1Answers: 2,586
    Answer ✓
This discussion has been closed.