/*

 * Ext JS Library 2.1

 * Copyright(c) 2006-2008, Ext JS, LLC.

 * licensing@extjs.com

 * 

 * http://extjs.com/license

 */



Ext.onReady(function(){



    // create the Data Store

    var store = new Ext.data.Store({

        // load using script tags for cross domain, if the data in on the same domain as

        // this page, an HttpProxy would be better

        url: 'http://www.asesorinteligente.com/admin/getallpreguntas.asp?dominio=1',



        // create reader that reads the Topic records

        reader: new Ext.data.XmlReader({

               // records will have an "Item" tag

               record: 'Item',

               id: 'IdPregunta',

               totalRecords: '@total'

           }, [

               // set up the fields mapping into the xml doc

               // The first needs mapping, the others are very basic

               'IdPregunta',

               'Pregunta', 'Respuesta', 'Claves'

           ])



        // turn on remote sorting

        //remoteSort: true

    });

    //store.setDefaultSort('lastpost', 'desc');



    // pluggable renders

/*    function renderTopic(value, p, record){

        return String.format(

                '<b><a href="http://extjs.com/forum/showthread.php?t={2}" target="_blank">{0}</a></b><a href="http://extjs.com/forum/forumdisplay.php?f={3}" target="_blank">{1} Forum</a>',

                value, record.data.forumtitle, record.id, record.data.forumid);

    }

    function renderLast(value, p, r){

        return String.format('{0}<br/>by {1}', value.dateFormat('M j, Y, g:i a'), r.data['lastposter']);

    }

*/

    // the column model has information about grid columns

    // dataIndex maps the column to the specific data field in

    // the data store

    var cm = new Ext.grid.ColumnModel([{

           id: 'topic', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })

           header: "Id", dataIndex: 'IdPregunta', width: 30

        },{

           header: "Pregunta", dataIndex: 'Pregunta', width: 150

        },{

           header: "Respuesta", dataIndex: 'Respuesta', width: 170

        },{

           id: 'last', header: "Claves", dataIndex: 'Claves', width: 150

        }]);



    // by default columns are sortable

    cm.defaultSortable = true;



    var grid = new Ext.grid.GridPanel({

        el:'topic-grid',

        width:700,

        height:500,

        title:'Preguntas',

        store: store,

        cm: cm,

        trackMouseOver:false,

        sm: new Ext.grid.RowSelectionModel({selectRow:Ext.emptyFn}),

        loadMask: true,

        viewConfig: {

            forceFit:true,

            enableRowBody:true,

            showPreview:false

        },

        bbar: new Ext.PagingToolbar({

            pageSize: 25,

            store: store,

            displayInfo: true,

            displayMsg: 'Desplegando preguntas {0} - {1} of {2}',

            emptyMsg: "0 Preguntas"

        })

    });



    // render it

    grid.render();



    // trigger the data store load

    store.load({params:{start:0, limit:25}});





});

