search in jqGrid
Asked Answered
F

1

1

i'm starter in jqGrid, i write this code for build jqGrid in ASP.NET

var grid = $('#list');
grid.jqGrid({
    url: 'jQGridHandler.ashx',
    postData: { ActionPage: 'CostTypes', Action: 'Fill' },
    ajaxGridOptions: { cache: false },
    direction: "rtl",
    datatype: 'json',
    height: 490,
    colNames: ['CostId', 'CostNo', 'CostName', 'Remark '],
    colModel: [
        { name: 'COST_ID', width: 100, sortable: true, search:true, editable: false,
            hidden: true, key: true, index: 'COST_ID' },
        { name: 'COST_NO', width: 100, sortable: true, editable: true },
        { name: 'COST_NAME', width: 350, sortable: true, editable: true },
        { name: 'REMARK', width: 300, sortable: true, editable: true }
    ],
    gridview: true,
    rowNum: 30,
    rowList: [30, 60, 90],
    pager: '#pager',
    sortname: 'COST_ID',
    viewrecords: true,
    rownumbers: true
});
grid.jqGrid('navGrid', '#pager', { add: false, edit: false, del: true, search: true },
    {},
    {},
    { url: "JQGridHandler.ashx?ActionPage=CostTypes&Action=Delete",
        reloadAfterSubmit: false },
    { multipleSearch: true});

when click in search icon and show search box when enter text example costNo=1 jqGrid not filter i think this action no work, please help me for implimet search in jqGrid thanks all

EDIT 01: when i add loadonce: true search work but when remove this option search don't work, please help me. thanks

Featherstone answered 6/9, 2012 at 22:58 Comment(0)
A
2

If you use loadonce: true the data will be loaded in the grid once. After that the datatype will be changed to "local" and all actions like reloading, sorting, searching (filtering) will be implemented locally without communication with the server.

If the user start searching the grid will be reloaded. If you use url: 'jQGridHandler.ashx', datatype: 'json' then the new request will be sent to the URL jQGridHandler.ashx. Some additional parameters inform the server that the data should be filtered, the _search parameter will be set to true. Because you use multipleSearch: true the rest information about the searching filter will be send in another parameter: filters. It's a string in JSON format. The format is described in the documentation. So the server have to decode the filters parameter and filter the grid data (typically one constructs WHERE part of the SELECT SQL statement based on the value of the filters parameter).

In the answer you will find the code example and can download the demo project.

Anklet answered 7/9, 2012 at 10:37 Comment(7)
this solution is good.but demo project worked on a table.now how can i use multiple tables like this query : #12360148 please help me tnxFeatherstone
@M.B: It seems to me absolute new question. Your new question is mostly about LINQ to Entities, restriction of LINQ, execution of native SQL statements with ExecuteStoreQuery or the usage of less comfortable EntityCommand in old .NET version... In many case I used to use old SqlCommand with SqlDataReader instead of Entity Framework and LINQ. In many cases one can use SQL Stored Procedures for the complex Queries. So there are a lot of aspects and the best solution depends on the project requirements.Anklet
@Oleg: How about using Views in Db? In this case you can still use the ObjectQuery and LinqToEntity.Wrapping
@HosseinMoradinia: It's also possible of cause. You can also use CTE (Common Table Expressions). In any way I would recommend you to write complex SQL statements in Transact-SQL instead of writing complex LINQ expressions in C#. In the case you will be sure that the SQL statements are really optimal.Anklet
hi mr Oleg, i have problem in this topic, please help me, #12556875 thanksFeatherstone
@M.B: I am at the customer this week. So I could look at the question at the evening probably. What I don't understand in your question: why you don't implement the permission for the column on the server side? jqGrid is client component. So in any way the server should not fill the data with the sensible information and play blanks instead. The server can additionally send to jqGrid the list of columns with blanks which should be made hidden.Anklet
@ Oleg: thanks for answer, when i hide column in client user can open source page and show all column in page, but when set permission in server end user when open source page Can not see all columns and change permission , thanks for help me.Featherstone

© 2022 - 2024 — McMap. All rights reserved.