How to control text input field in cell

How to control text input field in cell

pmconsultingpmconsulting Posts: 36Questions: 11Answers: 0

I am displaying a row value in an input field within a cell to allow users to change the local value. It is not and does not need to save this change to the server. I have assigned a class to all these inputs and have a jquery function that fires when the input changes.

The starting value is a number and I need to limit the range of adjustment to plus or minus 10% of the starting value.

My inputs look like this:

<input type="number" id="p_10826088015319" data-startval="21.60" class="prod_price" name="10826088015319" maxlength="6" size="5" value="21.60">

My jquery function looks like:

$('#rep01').on('change', '.prod_price', function() {
/* 1 - read data-startval
2 - calculate max & min values
3 - limit the entered value*/
});

How to I code this? Should I be using jQuery to addess the data-startval, or does datatables have its own method for doing this? I am not using editor mainly because I only need to allow these changes locally and do not need to save them to the server.

Answers

  • kthorngrenkthorngren Posts: 21,321Questions: 26Answers: 4,948
    edited January 2022

    Datatables doesn't have specific methods to handle the inputs. You would use Javascript or jQuery methods. You can use the jQuery data() method. Something like this should get the data-startval:

    $(this).data('startval');
    

    All of the steps you listed are standard Javascript. You might be able to use min and max attributes to control the range. But all of this is outside of Datatables. Stack Overflow is a good resource to research and ask about handling the inputs.

    This example will show how you can order by the inputs, if needed.

    If you need to do something in Datatables with the inputs you can look at cell().data() and cell().node(). If you have Datatables specific questions please provide a simple test case with what you have so we can work with it to find a solution.

    Kevin

  • pmconsultingpmconsulting Posts: 36Questions: 11Answers: 0

    Got it. I forgot quotes around the data value. Got it working now. Thank you so much!

  • kthorngrenkthorngren Posts: 21,321Questions: 26Answers: 4,948
    edited January 2022

    Is your table DOM sourced or are you using Datatalbes to load the data? If using Datatables how are you building the inputs?

    There may be somethings Datatables can do to help with setting the min / max values, like rowCallback. If you put together a simple test case we can take a look at what can be done with Datatables.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • pmconsultingpmconsulting Posts: 36Questions: 11Answers: 0

    I'm actually populating an html table using a custom post type plugin for WordPress called Toolset (toolset.com). This allows me to manage and assemble related data fairly easy. It does have some limits which require massaging the table data a bit. I need to calculate a few columns & change the column order, but I've navigated all of that so far.

    In my situation, I'm displaying products in the table which are assemblies of a case (one post type) containing one or more items (another post type) into a product (final post type).

    I'm only using datatables for building price lists. I allow registered users to create their own price lists for the customers they also manage. Once editing is complete, I save the data to a single field for that user so that they can return and continue working.

    Once they send the price list, the state gets locked so that they must make a new one. That way I maintain an accurate history of what each customer has received.

  • pmconsultingpmconsulting Posts: 36Questions: 11Answers: 0

    I did purchase a license for wpDataTables, which is datatables packaged as a plugin for WordPress. I couldn't get my head wrapped around dealing with relational data in the query builder they provide. Maybe I can find a tutorial on that process and use that plugin, but this method works.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    wpDataTables is third-party, it's not ours, so it would be worth asking the developer of that for support.

    Colin

Sign In or Register to comment.