Ext.toolbar.Toolbar Toolbar control instances in EXTJS4

Source: Internet
Author: User
Tags json

. Add menus, buttons, search features to the toolbar
We use the ListView control described above as the data display, put the ListView into a panel control, then add the toolbar to the top of the panel, and in the toolbar to implement the dataset's server-side search function.

First we define a data model and store:

The code is as follows Copy Code

[Js]
Ext.define (' Datas ', {
Extend: ' Ext.data.Model ',
Fields: [
{name: ' Intdata ', type: ' int '},
{name: ' StringData ', type: ' String '},
{name: ' Timedata ', type: ' Date '}
],
Proxy: {
Type: ' Ajax ',
URL: ' Toolbar1json ',
Reader: {
Type: ' JSON ',
Root: ' Rows '
}
}
});

var store = new Ext.data.Store ({
Model: ' Datas ',
Sortinfo: {field: ' Intdata ', direction: ' DESC '},
Autoload:true
});
Store.load ();

Server-side JSON output code:

The code is as follows Copy Code

[C # MVC]
Public Jsonresult Toolbar1json (string keyword)
{

var rows = BasicData.Table.Take (10). Select (x => New
{
Intdata = X.intdata,
StringData = X.stringdata,
Timedata = x.timedata.toshortdatestring ()
});
if (!string. IsNullOrEmpty (keyword))
{
rows = rows. Where (x => x.intdata.tostring () = = Keyword | | x.stringdata.contains (keyword) | | x.timedata.contains (keyword));
}
var json = new
{
Results = BasicData.Table.Count,
rows = Rows
};
Return JSON (JSON, jsonrequestbehavior.allowget);
}


Then define a ListView, from the last chapter

Now we're going to define a toolbar that adds tool buttons, plain text, split lines, and menus to the toolbar, and also implements search functionality:

The code is as follows Copy Code

[Js]
var filed1 = new Ext.form.Field ();

var Tbar = ext.create ("Ext.toolbar", {
Items: [' text ', '-', {
Xtype: "SplitButton",
Text: "Button"
}, {
Text: "Menu",
Menu
{
Items: [
{
Text: ' Option 1 '
}, {
Text: ' Option 2 '
}, {
Text: ' Option 3 ',
Handler:function () {
Ext.Msg.alert ("Hint", "Message from menu");
}
}
]
}
}, "->", "keywords:", filed1, {
Text: "Search",
Handler:function () {
Store.load ({params: {Keyword:filed1.getValue ()}});
}
}
]
});


Notice here that we passed the keyword keyword to the C # action parameter through the load store:

The code is as follows Copy Code

[Js]
{
Text: "Search",
Handler:function () {
Store.load ({params: {Keyword:filed1.getValue ()}});
}
}


Finally we define a panel and add ListView and toolbar to the Panel, noting that Tbar represents the top of the toolbar.

  code is as follows copy code

[Js]
& nbsp;   var panel = new Ext.panel ({
        renderto: "Div1",
        width:600,
        height:250,
        collapsible:true,
        Layout: ' Fit ',
        title: ' Demo toolbar ',
         Items:listview,
        tbar:tbar
   };


Well, let's see how it works:

We enter the keyword "6" After viewing the filter effect:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.