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

Allow to define named templates #631

Merged
merged 1 commit into from
Sep 8, 2014
Merged

Allow to define named templates #631

merged 1 commit into from
Sep 8, 2014

Conversation

OlegKi
Copy link
Contributor

@OlegKi OlegKi commented Aug 29, 2014

Hello Tony,

If one loads colModel from the server it's very practical to have properties which can be represented in JSON. If one want to use dataIni or other callbacks (for jQuery UI Datepicker, select2 or other controls) one can't load such column definition via JSON. jqGrid contains already practical feature in formatters. Formatters allow to extent $.fn.fmatter and assign string name to custom formatter and extend $.unformat to register the corresponding unformatter. In the way one can easy extend the list of predefined formatters.

jqGrid supports template property of colModel starting from version 3.8.2, but the value have to be an object. I suggest to make small modification of the code to allow to use for example template: "number". To define number template one need just define $.jgrid.cmTemplate.number using

$.extend($.jgrid, {
    cmTemplate: {
        number: {
            formatter: "number", align: "right", sorttype: "number", searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] }
        }
    }
});

I think that such small change can makes long code which uses jqGrid more small and more easy to maintain.

The demo demonstrates the usage of jqGrid after applying of suggested pull request.

You can consider to define some standard templates for numbers, intergers and dates at the beginning of grid.base.js.

Best regards
Oleg

If one loads `colModel` from the server it's very practical to have properties which can be represented in JSON. If one want to use `dataIni` or other callbacks (for jQuery UI Datepicker, select2 or other controls) one can't load such column definition via JSON. jqGrid contains already practical feature in formatters. Formatters allow to extent `$.fn.fmatter` and assign **string name** to custom formatter and extend `$.unformat` to register the corresponding unformatter. In the way one can easy extend the list of predefined formatters.

jqGrid supports `template` property of `colModel` starting from version 3.8.2, but the value have to be an object. I suggest to make small modification of the code to allow to use for example `template: "number"`. To define `number` template one need just define `$.jgrid.cmTemplate.number` using

    $.extend($.jgrid, {
        cmTemplate: {
            number: {
                formatter: "number", align: "right", sorttype: "number", searchoptions: { sopt: ["eq", "ne", "lt", "le", "gt", "ge"] }
            }
        }
    });

I think that such small change can makes long code which uses jqGrid more small and more easy to maintain.

[The demo](http://www.ok-soft-gmbh.com/jqGrid/templateAsString.htm) demonstrates the usage of jqGrid after applying of suggested pull request.
tonytomov added a commit that referenced this pull request Sep 8, 2014
Allow to define named templates
@tonytomov tonytomov merged commit b6b9113 into tonytomov:master Sep 8, 2014
OlegKi added a commit to free-jqgrid/jqGrid that referenced this pull request Jan 6, 2015
Use the feature included in jqGrid 4.7 based on the feature
tonytomov#631
flack pushed a commit to openpsa/jsgrid that referenced this pull request Jan 13, 2015
Use the feature included in jqGrid 4.7 based on the feature
tonytomov/jqGrid#631

Conflicts:
	js/jquery.jqGrid.min.js
	js/jquery.jqGrid.min.map
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

Successfully merging this pull request may close these issues.

2 participants