Jqrid-Search Dialog-How to localize groupOps Text

2019-03-02 05:36发布

问题:

I have a jqgrid which i enabled multiple search for and i wanna change the "AND" and "OR" group operation texts to their corresponding values in my native language.

I want to change

  • AND with VE
  • OR with VEYA

Here is my code :

    jQuery("#kontrollist").jqGrid('navGrid', '#controllistpager',
      {
        edit: true,
        add: true,
        del : true,
        search: true
      },
      { top: 10, left: 300, jqModal: false, closeOnEscape: true }, // edit options
      {top: 10, left: 300, jqModal: false, closeOnEscape: true, reloadAfterSubmit: true }, // add options
      {top: 100, left: 200, jqModal: false, closeOnEscape: true }, // del options
      // search options
      {
        top: 100, 
        left: 250, 
        jqModal: false, 
        closeOnEscape: true,
        groupOps: [{ op: "AND", text: "all" }, { op: "OR", text: "any"}],
        //showQuery: true,
        multipleSearch: true,
      }, 
      {top: 100, left: 200, jqModal: false, closeOnEscape: true} // view options
    );

I tried changing "op" attribute of "groupOps" like

groupOps: [{ op: "VE", text: "all" }, { op: "VEYA", text: "any"}],

and like

groupOps: [{ op: "AND", text: "VE" }, { op: "OR", text: "VEYA"}],

which both didnt work. Is there a way to change these values? Any help is appreciated, thanks in advance.

回答1:

It's a good question! +1 from me.

The current jqGrid code build corresponding <select> element using the same values for the displayed text and the value attribute used in the query. As a workaround I suggest you the define the function updateGroupOpText

var updateGroupOpText = function ($form) {
        $('select.opsel option[value="AND"]', $form[0]).text('My ADD');
        $('select.opsel option[value="OR"]', $form[0]).text('My OR');
        $('select.opsel', $form[0]).trigger('change');
    };

and use it as the event handler for onInitializeSearch and afterRedraw events:

jQuery("#kontrollist").jqGrid('navGrid', '#controllistpager',
    { add: false, edit: false, del: false },
    {}, {}, {},
    { // search options
        multipleSearch: true,
        onInitializeSearch: updateGroupOpText,
        afterRedraw: updateGroupOpText
    }
);

See the corresponding demo here, which displays the dialog like the following:

You should just change "My ADD" and "My OR" to the texts which you want.



标签: jqgrid