Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal - Get temporary rowData while editing #1054

Open
unle70 opened this issue Dec 15, 2023 · 3 comments
Open

Proposal - Get temporary rowData while editing #1054

unle70 opened this issue Dec 15, 2023 · 3 comments

Comments

@unle70
Copy link

unle70 commented Dec 15, 2023

Hi Tony,

I would like to propose one new feature, based on a situation I'm facing now.
When you define a cusom-type column which has "choices" defined (like: INPUT with DATALIST in my case), sometimes you want to make the list of choices "dynamic". What I mean is, when the field gets focus, the list of choices should be created based on the value of other fields in the row.

The problem is that currently, the "rowData" object which is passed to the custom element creation function, does not reflect any changes which have already been done in the edit form. The values are only the "official" ones, before the planned changes. This way I cannot really see the changes which have not yet been saved.

Getting the field values from the edit form is slightly complicated. You need to consider different types, including custom types. I see that you are doing this in your code (when creating the postdata), but this code is not available for me to call and use. I was wondering if there's any way you could make this service available to users, so that I could call it and get the CURRENT data of the edit form. BTW, I guess the same applies for inline editing.

Thanks,
Udi

@tonytomov
Copy link
Owner

tonytomov commented Dec 15, 2023

Hello Udi,

Thank you for the recommendation - much appreciate all your efforts regarding jqGrid .

To the request. I do not think that we need to add some additional code for what you need.
You can use simple command to get any current value in the form. Maybe you missed some paragraph into the doc.
In docs for editGridRow method when you scroll down you will see the following

=================================================================================
What is need to know?

When the form is constructed we set the following rules:

  • Hidden fields are included in the form with the display:none property of the table row
  • The id of the editable element is constructed from the name of the colModel array - the property name
  • The name of the editable element is constructed from the name of the colModel array - the property name
  • For ease in manipulating the elements in an edit form, every table row in the form that holds the data for the edit has a id which is a combination of "tr_" + name (from colmodel). Example:
<form ....>
  <table>
    <tr id='tr_myfield'>  
      <td> Caption</td> <td>edited element named, in colModel, as "myfield"</td>
    </tr> ...
  </table>
</form>
  • Every time the form is lunched it is recreated. The recreateForm parameter is set to true just remember the position of the form
  • The form has the following attributes:
    • name - FormPost
    • class - FormGrid
    • id - FrmGrid_ + the id of the grid

This allow us to easily show or hide some table rows depending on conditions using beforeShowForm event

==================================================================================

Having this you can get easy any current value from the form like:

$("#CustomerID").val();

or better if the grid has id grid

$("#CustomerID", "#FrmGrid_grid").val();

In case you have different input types like checkbox, radio and etc you can simply
check its type like

var field_type = $("#CustomerID", "#FrmGrid_grid")[0].type

and do appropriate o get the right value

Similar to this there is description for cell edit and inline edit.

Hope this will solve your problem

Best Regards,
Tony

@tonytomov
Copy link
Owner

tonytomov commented Dec 15, 2023

or another easy current form value get (except maybe for some complex custom elements)

If the jqGrid has id = grid

var formid = "#"+"FrmGrid_grid",
   fields = $(formid).serializeArray(),
   griddata = {};
$.each(fields, function(i, field){
	griddata[field.name] = field.value;
});

or using this thread you can add your own function:

 /*!
 * jQuery serializeObject - v0.2 - 1/20/2010
 * http://benalman.com/projects/jquery-misc-plugins/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */

// Whereas .serializeArray() serializes a form into an array, .serializeObject()
// serializes a form into an (arguably more useful) object.

(function($,undefined){
  '$:nomunge'; // Used by YUI compressor.
  
  $.fn.serializeObject = function(){
    var obj = {};
    
    $.each( this.serializeArray(), function(i,o){
      var n = o.name,
        v = o.value;
        
        obj[n] = obj[n] === undefined ? v
          : $.isArray( obj[n] ) ? obj[n].concat( v )
          : [ obj[n], v ];
    });
    
    return obj;
  };
  
})(jQuery);

Usage

var current_form_data = $( "#"+"FrmGrid_grid").serializeObject();

@unle70
Copy link
Author

unle70 commented Dec 15, 2023

Hi Tony,

Well, if I look at your code for constructing "postdata", indeed this is what I see. Generally speaking, I would need to copy everything you have there, like: Getting simple values (input), getting values from standard type fields (select, buttons, etc.), getting values from custom fields, and eventually unformatting. You have done all of this very well, so I was just hoping I would have a way of using your code. This way, if ever you add more standard types, or any additional functionality, it would automatically be supported and available to me.

But I understand it if you don't see potential for other people using this feature.

Thank you for creating and maintaining jqGrid all these years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants