tudor-malene/Easygrid

ColumnConfig.jqGrid.searchoptions.sopt cannot be overwriten (jqgrid)

Opened this issue · 1 comments

The sopts are currently defined by type in the EasyGridConfig.
When i specify sopts in my grid config like that:

columns {
  column_name {
    jqgrid {
      searchoptions {
        sopt( ["eq"] )
      }
    }
  }
}

it will not be used.

Thats because EasyGridInitService.addDefaultValues will call easygridDispatchService.callGridImplAddDefaultValues. In our case (for jqgrid) its JqueryGridService.addDefaultValues. There the sopt defined in the controller is overwritten by the values defined in the config.

Here is the code snipped that will cause the problem:

if (columnConfig.enableFilter && columnConfig?.filterType) {
    List operators = grailsApplication.config.easygrid.columns.defaults.filterOperators[columnConfig.filterType]
    columnConfig.jqgrid.searchoptions << [sopt: operators.collect {
        JsUtils.jqgridFilterOperatorConverter(it)
    }]
}

It would be really great if you could adjust the code in a way that it will only overwrite the sopt if they are not defined in the grid config. This way we could customize the sopts per column.

Had the same issue.
Here my solution:

Append this in EasygridConfig.groovy

org.grails.plugin.easygrid.grids.JqueryGridService.metaClass.addDefaultValues = { GridConfig gridConfig, defaultValues ->
    if (gridConfig.enableFilter) {
        gridConfig.columns.each { ColumnConfig columnConfig ->
            if (columnConfig.enableFilter && columnConfig?.filterType) {
                if(!columnConfig?.jqgrid?.searchoptions?.sopt){
                    java.util.List operators = grails.util.Holders.grailsApplication.config.easygrid.columns.defaults.filterOperators[columnConfig?.filterType]
                    columnConfig.jqgrid.searchoptions << [sopt: operators.collect {
                        JsUtils.jqgridFilterOperatorConverter(it)
                    }]
                }
            }
            //if no property defined
            if (columnConfig.jqgrid.editable == null) {
                columnConfig.jqgrid.editable = (columnConfig.property != null)
            }
        }
    }
    //disable sorting in the UI if the column is not sortable
    gridConfig.columns.each { ColumnConfig columnConfig ->
        columnConfig.jqgrid.sortable = columnConfig.sortable
    }
}