javascriptphpjqxgrid

Select a row by the value of one cell in jqxGrid


I've got a little question about the use of jqxGrid from jqWidgets. I'm trying to select a row of my table dynamically from another page. I explain myself:

My first page contains a list of users. I want that when I choose an user on this list, it opens a new page with, by exemple, the ID of my user returned in GET through PHP. And then, I want to generate a new grid, with less information, but with the user already selected.

I've found how to select a row by her index $('#grid').jqxGrid('selectrow', 10); but it's not working, because if one table is sorted or filtered, the index is changed...

So, is there any way to do this ?

Here's the code wich is called when selecting a row on first table:

$('#search_right').bind('rowselect', function(event){
    var iSocID = $('#search_right').jqxGrid('getcellvalue', event.args.rowindex, 'id');
    $("#soci_right").load('activites/soc.search.php?a=form&id='+iSocID);
    $('#content').jqxTabs('select', 3);
});

And here's the generation code of my second list:

var url = 'activites/soc.search.php';
    var source = {
        datatype: "json",
                datafields: [
                    { name: 'name', type: 'string'},
                    { name: 'id', type: 'int'},
                ],
                id: 'id',
                url: url,
                root: 'data'
    };

    dataSource = new $.jqx.dataAdapter(source);

    $("#soci_table").jqxGrid({
        source: dataSource,
        theme: jqxGlobalTheme,
        columnsresize: true,
        sortable: true,
        filterable: true,
        showfilterrow: true,
        columns: [
            { text: 'Name', dataField: 'name'},     
            { text: 'ID', dataField: 'id',  hidden:true},
        ]
    });

Solution

  • After contacting the support of jqWidgets (who couldn't help me......) I've made a little snippet that does the tricks... But I think jqWidget should add this as a default functionnality of jqxGrid !

    I paste you my code here, hope it'll help some of you !

        $('#search_right').bind('rowselect', function(event){
        var iSocID = $('#search_right').jqxGrid('getcellvalue', event.args.rowindex, 'id');
    
             // Create filter
            var filtergroup = new $.jqx.filter();
            var filtervalue = iSocID;
            var filtercondition = 'EQUAL';
    
            var filter1 = filtergroup.createfilter('stringfilter', filtervalue, filtercondition);
    
            var filter_or_operator = 1;
            filtergroup.addfilter(filter_or_operator, filter1);
    
            $("#soci_table").jqxGrid('addfilter', 'id', filtergroup);
    
            // Apply filter
    
            $("#soci_table").jqxGrid('applyfilters');
    
            // Select row
    
            $('#soci_table').jqxGrid('selectrow', 0);
    
            // Remove filter
    
            $("#soci_table").jqxGrid('clearfilters');
        });